How to get the original request url from a servlet/jsp after multiple servlet forwards

I found a better answer in this post [ How do you detect the URL in a Java Servlet when forwarding to JSP? ]

On the target JSP use:

request.getAttribute("javax.servlet.forward.request_uri")

To find out what the original URL was.

It doesn't require you to take any extra steps on the forwarding servlet


You can use a filter to putting origin address to request attribute and then read it from jsp

Filter mapped to /booking/* execute:

request.setAttribute("origin", request.getRequestURL());

Jsp:

${pageContext.request.attribute["origin"]}

This works because filter has set REQUEST dispatcher by default. It means filter executes only for direct client requests not for forwarding/including


${requestScope["javax.servlet.forward.request_uri"]}

or with single quotes

${requestScope['javax.servlet.forward.request_uri']}