Vivek Vivek - 4 months ago 26
Java Question

how to get URL from address bar in JSP

Lets say I hit


http://localhost/webapp/wcs/stores/servlet/en/marksandspencer/l/women/dresses/party-and-cocktail-dresses



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?

Answer

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

Comments