Web tier: servlets, JSP, Web frameworks: Application Context from within Servlet.init()?

  1. Application Context from within Servlet.init()? (2 messages)

    Is there any way of getting the context path, (for example, /myapp), from within the Servlet.init() method. I know I can easily get it with the request object using request.getContextPath(), but I can't figure out how to get it from the init() method.
  2. You can easily get the application context:

    public void init(ServletConfig config) throws ServletException {
        // see?
        ServletContext ctx = config.getServletContext();

    hope this helped!

  3. But I can't get the servlet path from the context, which is what I want. I want to get string "/context" which is defined for this servlet.

    Specifically, I want to get the same information that I can get from the HttpServletRequest.getContextPath() method.