Vivek Vivek - 3 months ago 16x
Java Question

how to get URL from address bar in JSP

Lets say I hit


and this internally redirects me to custom 404.jsp page, But URL remain same in address bar.

I tried this code -
<%= request.getAttribute("javax.servlet.forward.request_uri") %>;
and it's returning me the path of 404.jsp

How can I get the entered URL which is there in address bar?


I think you were close. javax.servlet.forward.request_uri is for normal forwarding, but for 404, you need javax.servlet.error.request_uri.