This question shows that when forwarding, the information in the request object is updated to reflect the new file. So for example, when:
user requests "/abc" -> servlet is invoked > forwards to /def.jsp
Then in def.jsp
${request.requestURI}
will be /def.jsp
rather than /abc
. If one wants to obtain the original requested URI (or any other information, like servlet path, etc):
request.getAttribute("javax.servlet.forward.request_uri");
All fine, but how can I access this via JSTL. ${javax.servlet.forward.request_uri}
doesn't work. The dot is considered an operator, rather than part of the name. In other cases, this is solved by putting the name in square brackets and quoting it. But here there is no map object, and ${['javax.servlet...']}
does not work.
So, how?
(I can put it in a "dotless" attribute in the servlet, but that's a workaround)
As far as I remember, it's something like this:
${requestScope["javax.servlet.forward.request_uri"]}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With