Is there a way I can get the context name and the servlet path from the init method of a servlet?
Created May 8, 2012
Uwe Hanisch Well, up to now the only way to get your context path
is to call getContextPath() on a HttpServletRequest object.
But this object you receive only with a HTTP request to your
HttpServlet. E.g.:
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException { String ctxPath = req.getContextPath(); ... }I think it would be usefull, if you can obtain the context path also from the ServletContext. But at the moment I see no chance to get the context path in the HttpServlet init() method.