I am developing this Spring app where I "suddenly" decided to match error pages such as 404 (the famous HTTP 404 Not Found) to a more user friendly page.
After quick research, I find that adding this code to web.xml
does the trick
<error-page>
<error-code>404</error-code>
<location>/error/404.jsp</location>
</error-page>
Here we assume that I added the required 404.jsp
file to /webapp/error/
directory.
Related articles:
However after running the app and typing a random url (such as http://localhost:8080/SpringWebApp/myRandomUrladasdad
) I find myself redirected to another standard 404 page - not mine.
FYI this is my entire web.xml
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>imageServlet</servlet-name>
<servlet-class>sphbmveclp.account.controllers.ImageFromDirServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>imageServlet</servlet-name>
<url-pattern>/image/*</url-pattern>
</servlet-mapping>
<error-page>
<error-code>404</error-code>
<location>/error/404.jsp</location>
</error-page>
After an unreasonnable amount of googling I ran into this:
http://www.mkyong.com/spring-mvc/404-error-code-is-not-working-in-spring-mvc/
So I assumed I had something good here. I assumed my vast <url-pattern>/</url-pattern>
may have been causing all this trouble. So I changed it to something more specific <url-pattern>/admin/*</url-pattern>
in this case.
But no luck, It is still not working as expected.
Any idea?