What does “Context” in “ServletContext” mean?

前端 未结 6 1838
独厮守ぢ
独厮守ぢ 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:18

    A ServletContext is the runtime representation of the web application.

    0 讨论(0)
  • 2021-01-31 11:23

    Context means web app here.

    A ServletContextListener gets notified when a Web App is started or stopped. That way you can run tasks automatically that need to be run when the web app starts or stops.

    0 讨论(0)
  • 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
    0 讨论(0)
  • 2021-01-31 11:34

    The name is indeed, IMO, very badly chosen.

    We must read ServletContext as "the general context of a servlet API based web application". Whereas we must read ServletConfig (another standard class) as "The config of a servlet".

    They should IMO have named ServletContext as "WebAppContext" or "ApplicationContext", and ServletConfig as "ServletContext".

    BTW, in JSP, the scope linked to a JspPage is named "page"; the scope linked to a HttpServletRequest is named "request"; the scope named to a HttpSession is named "session", and the scope linked to a ServletContext is named ... "application".

    0 讨论(0)
  • 2021-01-31 11:36

    "Context" means.. context - it has contextual information and functionality for a particular web application:

    • application-wide parameters
    • application event listeners
    • metadata about the application

    ServletContext is the context of a Java web application (because it uses servlets)

    0 讨论(0)
  • 2021-01-31 11:37

    ServletContext implies Context or Runtime environment of servlet. Servlets runs in Servlet containers like tomcat. Servlet container creates and provides runtime environment for the servlet to get executed and it manages its lifecycle. It also holds other information, as :-

    • application-wide parameters
    • application event listeners
    • metadata about the application
    0 讨论(0)
提交回复
热议问题