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

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

Shashank Raju
1#
Shashank Raju Published in 2018-02-13 15:35:36Z
 I'm using the following config in web.xml to redirect to error pages  401 /  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
2#
Christopher Schultz Reply to 2018-02-18 18:32:58Z
 The  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  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
3#
 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.
Processed in 0.379746 second(s) , Gzip On .