Home tomcat - how to change url after redirecting to an error page
Reply: 2

tomcat - how to change url after redirecting to an error page

Shashank Raju
Shashank Raju Published in 2018-02-13 15:35:36Z

I'm using the following config in web.xml to redirect to error pages


when 401 error occurs it is redirecting to '/' but the URI is preserved.

let's say if I'm trying to access 'localhost:8080/account' resource which needs auth, then the redirect is happening but URL is still 'localhost:8080/account'.

I was wondering how to redirect to '/' and have the url to be 'localhost:8080/'

Christopher Schultz
Christopher Schultz Reply to 2018-02-18 18:32:58Z

The <error-page> directives set-up in-process forwards, not client-redirects (which would be 3xx responses).

If you want to convert a 401 into a 302, then set your <error-page> to point to a JSP that changes the response code to 302 with a Location response header.

Note that changing a 401 response to a 302 response (which will probably end up with a 200 when the redirect is followed) kind of defeats the purpose of having the 401 response in the first place.

Mick Reply to 2018-02-13 16:12:03Z

You want to tell the client that localhost:8080/account does not exist, so this resource should report a 404 status. Why should it do a redirect to the root directory? The root directory exists, so redirecting to the root and returning a 404 would be just wrong.

The error-page directive just tells tomcat where to pull a custom HTML style for your 404 pages from. The client should NOT be redirected to other resources, because - as already stated - that would alter the semantics alltogether.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.379746 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO