Java Struts 404 Error Page Example
The “HTTP Status 404” error code shows that the system can not find the page or resource you requested. In practice, you should display your custom 404 error page. However, it is handle in web.xml , not in Struts framework. For example,
1 2 3 4 5 6 7 8 |
<web-app> ... <error-page> <error-code>404</error-code> <location>/pages/error404.jsp</location> </error-page> </web-app> |
When system hit the 404 error, it will forward to your custom 404 error page “/pages/error404.jsp“.
struts-config.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>Maven Struts Examples</display-name> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <error-page> <error-code>404</error-code> <location>/pages/error404.jsp</location> </error-page> </web-app> |