Any easy way to get Context Path from HttpServletRequest object
843841Aug 21 2007 — edited Aug 21 2007Hi, 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