getRequestURL is returning NULL
843842May 1 2008 — edited May 2 2008I am trying to get the server path so that I may construct a complete URL in my application.
For example, if the servlet was accessed via:
"http://www.someplace.com/myApp/myServlet"
then I want this part:
"http://www.someplace.com/myApp"
So I used HttpUtils.getRequestURL() to reconstruct the full path and just snipped off the beginning part of it. It worked fine.. but the problem is HttpUtils is deprecated. We use Java 1.4.2 with J2EE 1.4. They don't want me to use deprecated methods in this project.
There is a method directly under HttpServletRequest called getRequestURL, but it returns NULL ! The StringBuffer it returns is actually null, so if I try doing toString() on it I get a NullPointerException.
Can I reliably reconstruct the same URL without using getRequestURL? I seem to be able to do it in my test environment but I have no idea how it would play out on a production server which has a "www" in the URL. My test environment is just "localhost".