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!

Any easy way to get Context Path from HttpServletRequest object

843841Aug 21 2007 — edited Aug 21 2007
Hi, this problem seems to be around a while. I'm trying to get a context path from my URL in a custom tag using the HttpRequest object.
i.e if my URL is http://mysite:7002/MyPages/pageOne.do
I'm trying to get the 'MyPages' bit

Its easy to get the server name (i.e. 'mysite') and port (7002) but I haven't found an easy way to get the context path from the request or the ServletContext. I don't want to have the URI's hard-coded anywhere so can't use ServletContext.getContextPath. Also ServletContext.getRealPath("/") is returning null

Anyone any ideas?
Thanks,
Colin
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 18 2007
Added on Aug 21 2007
2 comments
398 views