You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ben Walding <be...@walding.com> on 2002/09/04 10:51:32 UTC

Replacement 401 pages

Greetings all,
Maybe someone can answer the following conundrum for me!

I've replaced my 401 page with a servlet reference using the error-page 
section of the web.xml. I'd like the servlet to display different 
content based on what was accessed. At present I have to use javascript 
(document.location.href) to do this at the client end.   Surely there is 
a better way!?!

The servlet "works" and forces authentication (once I'd added a Realm 
header and 401 status code), however I can't detect the cause of the 
authentication in the authentication page servlet ("I" know what 
resource caused the authentication page to be called, but the servlet 
doesn't seem to have any simple way to determine this). All I need is a 
header being passed in on the request object, but if there is a spec 
defined way to do this... I'm all ears...

Since it isn't using a redirect (just some internal shenanigan), there 
doesn't seem to be any headers to help me out.

Cheers,

Ben


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Replacement 401 pages

Posted by Tim Funk <fu...@joedog.org>.
See section 9.8 of the spec:
A web application may specify that when errors occur, other resources in 
the application are used. These resources are specified in the 
deployment descriptor. If the location of the error handler is a servlet 
or a JSP, the following request attributes can be set:
- javax.servlet.error.status_code
- javax.servlet.error.exception_type
- javax.servlet.error.message
- javax.servlet.error.exception
- javax.servlet.error.request_uri

In your JSP or servlet, use request.getAttribute("...") for any of the 
above to get more details about the error. Then you can forward() or 
"whatever" based on your business logic.


Ben Walding wrote:
> Greetings all,
> Maybe someone can answer the following conundrum for me!
> 
> I've replaced my 401 page with a servlet reference using the error-page 
> section of the web.xml. I'd like the servlet to display different 
> content based on what was accessed. At present I have to use javascript 
> (document.location.href) to do this at the client end.   Surely there is 
> a better way!?!
> 
> The servlet "works" and forces authentication (once I'd added a Realm 
> header and 401 status code), however I can't detect the cause of the 
> authentication in the authentication page servlet ("I" know what 
> resource caused the authentication page to be called, but the servlet 
> doesn't seem to have any simple way to determine this). All I need is a 
> header being passed in on the request object, but if there is a spec 
> defined way to do this... I'm all ears...
> 
> Since it isn't using a redirect (just some internal shenanigan), there 
> doesn't seem to be any headers to help me out.
> 
> Cheers,
> 
> Ben
> 
>  


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>