Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getRequestURL() of HttpServletRequest not returning exact URL

Tags:

java

tomcat

I am running a spring framework based web app on Tomcat. My requirement is that any request coming to the server should come to a single servlet. so i made the following configuration in conf/web.xml

<error-page>
    <error-code>404</error-code>
    <location>/displayMsg.do</location>
</error-page>

So when the user access http://myhost/xyz , request.getRequestURL() returns http://myhost/displayMsg.do

I think the only reason for the requestURL() to return this url is because of the the error page configuration i made. May be because tomcat overwriting the url to this string.

Is it possible to get the exact URL in this case? Please help

like image 592
ihavprobs Avatar asked Sep 18 '26 14:09

ihavprobs


1 Answers

I ran into this same problem a couple weeks ago.

You can pull the actual url using

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

like image 197
NorrisSoftware Avatar answered Sep 21 '26 03:09

NorrisSoftware



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!