I have an HttpServletRequest
object.
How do I get the complete and exact URL that caused this call to arrive at my servlet?
Or at least as accurately as possible, as there are perhaps things that can be regenerated (the order of the parameters, perhaps).
Somewhat late to the party, but I included this in my MarkUtils-Web library in WebUtils - Checkstyle-approved and JUnit-tested:
Probably the fastest and most robust answer here so far behind Mat Banik's - but even his doesn't account for potential non-standard port configurations with HTTP/HTTPS.
See also:
HttpUtil being deprecated, this is the correct method
I use this method:
The
HttpServletRequest
has the following methods:getRequestURL()
- returns the part of the full URL before query string separator character?
getQueryString()
- returns the part of the full URL after query string separator character?
So, to get the full URL, just do:
Combining the results of
getRequestURL()
andgetQueryString()
should get you the desired result.