You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Bragg, Casey" <Ca...@allegiancetelecom.com> on 2001/07/19 21:43:24 UTC

Using Error Pages? : Still stuck... More info...

I left some info out of my question...

(BTW - the mailing list archive is filled with this question over and over
with few solutions)

My ROOT context has a valve entry in it.  The valve is running the
sendError.

The question :
   Why does my custom 404 error page work, but my nearly identical 403 page
does not work (I get the standard 403 message instead)?

>From server.xml : 

   <Context path="" docBase="ROOT" debug="999">
      <Valve className="tman.ManagerValve"/>
   </Context>

>From tman.ManagerValve.invoke() (tman.MAnagerValve extends
org.apache.catalina.valves.ValveBase) : 

        // to deny
          if ((requestURI!=null)&&(requestURI.indexOf("/deny")>=0)) {
		ServletResponse sres = response.getResponse();
		if (sres instanceof HttpServletResponse) {
		    HttpServletResponse hres = (HttpServletResponse) sres;
		    hres.sendError(HttpServletResponse.SC_FORBIDDEN);
                    log("process end : " +
HttpServletResponse.SC_FORBIDDEN);
		    return;
		}
          }

        // to allow
		context.invokeNext(request, response);
                log("process end");
		return;

==============================================
Casey Bragg - Software Engineer
Allegiance Telecom, Inc.  Dallas, TX
469-259-2702 - casey.bragg@allegiancetelecom.com
==============================================


-----Original Message-----
From: Bragg, Casey [mailto:Casey.Bragg@allegiancetelecom.com]
Sent: Thursday, July 19, 2001 10:44 AM
To: tomcat-user@jakarta.apache.org
Subject: Using Error Pages


Hello : 

I can't get my 403 (forbidden) error page to show up.  Instead, I get the
standard 403 error message on my browser (yes, friendly error messages are
turned off on IE).  My 404 page works and its virtually identical to my 403
page.  What am I doing wrong?



I have the following entry in my ROOT/WEB-INF/web.xml :

   <error-page>
      <error-code>403</error-code>
      <location>/security/status/forbidden.jsp</location>
   </error-page>
   <error-page>
      <error-code>404</error-code>
      <location>/security/status/notfound.jsp</location>
   </error-page>



The following messages appear in my logs : 

XmlMapper: new null org.apache.catalina.deploy.ErrorPage error-page
ErrorPage[errorCode=0, location=null]
XmlMapper: org.apache.catalina.deploy.ErrorPage.setErrorCode( 403)
XmlMapper: org.apache.catalina.deploy.ErrorPage.setErrorCode( )
XmlMapper: org.apache.catalina.deploy.ErrorPage.setLocation(
/security/status/forbidden.jsp)
XmlMapper: org.apache.catalina.deploy.ErrorPage.setLocation( )
XmlMapper: Calling org.apache.catalina.core.StandardContext.addErrorPage
ErrorPage[errorCode=403, location=/security/status/forbidde
n.jsp]
XmlMapper: pop error-page org.apache.catalina.deploy.ErrorPage:
ErrorPage[errorCode=403, location=/security/status/forbidden.jsp]
XmlMapper: new null org.apache.catalina.deploy.ErrorPage error-page
ErrorPage[errorCode=0, location=null]
XmlMapper: org.apache.catalina.deploy.ErrorPage.setErrorCode( 404)
XmlMapper: org.apache.catalina.deploy.ErrorPage.setErrorCode( )
XmlMapper: org.apache.catalina.deploy.ErrorPage.setLocation(
/security/status/notfound.jsp)
XmlMapper: org.apache.catalina.deploy.ErrorPage.setLocation( )
XmlMapper: Calling org.apache.catalina.core.StandardContext.addErrorPage
ErrorPage[errorCode=404, location=/security/status/notfound
.jsp]
XmlMapper: pop error-page org.apache.catalina.deploy.ErrorPage:
ErrorPage[errorCode=404, location=/security/status/notfound.jsp]



My code is purposely throwing the following : 

HttpServletResponse hres = (HttpServletResponse) sres;
hres.sendError(HttpServletResponse.SC_FORBIDDEN);

Thanks!

...Casey

==============================================
Casey Bragg - Software Engineer
Allegiance Telecom, Inc.  Dallas, TX
469-259-2702 - casey.bragg@allegiancetelecom.com
==============================================

Re: Using Error Pages? : Still stuck... More info...

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Thu, 19 Jul 2001, Bragg, Casey wrote:

> I left some info out of my question...
> 
> (BTW - the mailing list archive is filled with this question over and over
> with few solutions)
> 
> My ROOT context has a valve entry in it.  The valve is running the
> sendError.
> 
> The question :
>    Why does my custom 404 error page work, but my nearly identical 403 page
> does not work (I get the standard 403 message instead)?
> 

This isn't going to work :-(

The reason is that Valves are processed *before* the webapp-related things
are, so things like error page directives are not invoked on the return
value from a Valve.

A possible alternative would be to implement your ManagerValve
functionality as a Filter instead.  That way, it would be processed
"inside" the webapp, and error pages would be applied.

As an extra added bonus, you would be portable to other containers as well
:-).

Craig