struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Nenning <Christoph.Nenn...@lex-com.net>
Subject Re: Problems configuring own error pages for status codes manually set
Date Mon, 17 Feb 2014 13:58:15 GMT
Instead of response.sendError() you can try to use a struts http header 
result:


http://struts.apache.org/development/2.x/docs/httpheader-result.html


hope that helps


Regards,
Christoph


> 
> 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
> 

This Email was scanned by Sophos Anti Virus

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message