Pages

Customized 404 Error Page in Struts

By Default, Struts will show a default 404 error page. If you want custom error page, you want to declare xml attributes in web.xml. Mention the error code and JSP page in xml attribute when the particular error happen it redirects to the custom page in your directory not to the default page.
Put your error404.jsp in WebContent directory in your application.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
  <display-name>Custom Error Page</display-name>

  <!-- Standard Action Servlet Configuration -->
  <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>2</load-on-startup>
 </servlet>

  <!-- Standard Action Servlet Mapping -->
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

  <!-- The Usual Welcome File List -->
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <!-- The Custom Error Page List -->
  <error-page>
    <error-code>404</error-code>
    <location>error404.jsp</location>
  </error-page>

</web-app>