Search code examples
servletsinitcontextpath

Get context path in init method in Servlet 2.3 (so no ServletContext#getContextPath() available)


I'm using servlet 2.3 for my project development due to some legacy code we have. Is there a way to get the context path in the init method or any other way of the servlet?

I know it's possible on higher versions of Servlet and can get it in hacky way using the getRealPath() method on servlet 2.3. However I'm still looking for a better and cleaner code.


Solution

  • I wasn't able to do this. The best way I found was to move to 2.5 spec.

    Posting answer just in case anyone is trying the same.