Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

getRequestURL is returning NULL

843842May 1 2008 — edited May 2 2008
I 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".
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 30 2008
Added on May 1 2008
2 comments
1,531 views