浅谈ServletContext、ServletConfig、ServletContextListener

What is a domain object?

    Domain objects: saving data acquisition and data, used to share data between different resources.

Web development in the field of four objects:

Press range from small to large : page (jsp active) → request (first request) → session (a session) → application (current web application)

  • page domain refers pageContext.
  • request refers to a domain HttpServletRequest
  • It refers to a domain session HTTPSession
  • It refers to the application domain ServletContext

page: jsp page is executed, the life cycle begins, jsp page is finished, the end of the life cycle.

request: the user sends a request to start the server returns a response to the request end, the end of the life cycle.

session: the user opens the browser to access, create a session (beginning), session times out or declared invalid, the object end of the life cycle.

    Note: A client corresponds to a Session, the same user using two browsers to access the same page, there will be two Session, open the same browser at any time, using a Session with

application: web application load time of creation. Web application server is removed or closed, objects destroyed. End of Life.

 

ServletConfig object

  • What is ServletConfig object?

  ServletConfig object, called Servlet configuration object. Mainly used to load initialization parameter configuration file.

  • Creating opportunity

  ServletConfig servlet object after object creation, created before calling the init method, the init method with the Config object passed to the servlet.

 

ServletContext object

  • What is ServletContext object?

ServletContext object called servlet context object . The object is only to create an object in a web application, a WEB application corresponds to a
ServletContext. Representative of the current web application environment. In the current web application servlet all share a ServletContext object.

  • ServletContext object's life cycle

ServletContext object life cycle of the project started and start with the WEB, WEB project with the closure and destruction.

 

ServletContextListener objects

ServletContextListener object that can monitor the life cycle of ServletContext object is actually listening lifecycle of Web applications. So when notification context (context) initialization and destruction, ServletContextListner very useful .

 

Guess you like

Origin blog.csdn.net/weixin_42153410/article/details/93469033