What does “Context” in “ServletContext” mean?

前端 未结 6 1839
独厮守ぢ
独厮守ぢ 2021-01-31 11:04

Method getServletContextName() returns the name of the \"web application\". That means, \"ServletContext\" is nothing but \"web application\". Ok.

API defin

6条回答
  •  醉梦人生
    2021-01-31 11:32

    ServletContext is interface that contain a set of methods to communicate with its own servlet container.

    • Context that stand as a one per web application on per jvm .

    That allow servlets to gain access to the context for various parts of the server to communicate.

    Life Cycle of ServletContext

    1. Servlet container reads the DD (Deployment Descriptor – web.xml) and creates the name/value string pair for each when web application is getting started.
    2. Container creates the new Instance of ServletContext.
    3. Servlet container gives the ServletContext a reference to each name/value pair of the context init parameter.
    4. Every servlet and JSP in the same web application will now has access to this ServletContext. ServletConfig vs ServletContext

      • ServletContext is available to all servlet & jsp in web application while ServletConfig will be available only specific servlet.
      • Servlet config is one per servlet and Servlet context is one per web application

提交回复
热议问题