Hello,

I try to use/configure my own error pages for my struts 2 Application (struts version: 2.3.15.3, Apache Tomcat 6.0). I configure the two error pages for the status codes 403 (not authenticted) and 404 (page not avaiable) in the web.xml (see below) and place the desired pages in the approprate directory of the web-application.

The code 403 will be explicity set by the business logic (check for authentication) using the sendError method of HttpServletResponse:

protected void handleNotAuthorized(HttpServletRequest request, HttpServletResponse response )
               throws ServletException, IOException
{
    /* some Code to check authentication */
     if (testAuth){
            logger.info("Authorization failed. Show 403 page!");
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
      }
}

Here a the relevant experpt of my web.xml:
----------------------------------------------------------------------
    <filter>
        <filter-name>struts-prepare</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
    </filter>

    <filter>
        <filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
    </filter>

    <filter>
        <filter-name>struts-execute</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
    </filter>

   <filter-mapping>
        <filter-name>struts-prepare</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>

    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>*.html</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>struts-execute</filter-name>
       <url-pattern>/*</url-pattern>
       <dispatcher>REQUEST</dispatcher>
       <dispatcher>FORWARD</dispatcher>
       <dispatcher>INCLUDE</dispatcher>
       <dispatcher>ERROR</dispatcher>
    </filter-mapping>

    <error-page>
        <error-code>403</error-code>
        <location>/403.jsp</location>
    </error-page>
    <error-page>
        <error-code>404</error-code>
        <location>/404.jsp</location>
    </error-page>
------------------------------------------------

For 404 everything works fine: If I request a non-existing page, my configured error page will be displayed.

But when I try to request a non-authenticated page (status 403), the HTTP-Response has the correct status code 403 but my configured error page will not be displayed. Instead the browser shows a default page (empty page in case of firefox).

Has anyone an idea, how to solve the problem?

Thanks,
Thomas

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to