Daily stupid-about the four domain objects of Servlet today, I suddenly don’t recognize servletContext and appctionContext

After searching for a long time, I remembered that it was a domain object
. . Container. . . Different containers have different scopes

1. The scope of servletContext (application) is the largest, which acts in the entire web application;

Creation time: created when the web application is published to the Tomcat server

Destruction time: the Tomcat server is shut down or removed from the Tomcat server

2. The scope of session is second, and the default effect is in a session (a session: open a browser to access a web application to close the browser)

Creation time: created when request.getRequestSession() is called for the first time (there are two operations inside this method: a. If the current client does not have a session, create a session; b. If the current client has a session, it will be based on cookie Find the corresponding session in the JSESSIONID and return)

Destruction time: a. Server (abnormally) closed b. Session expired (invalid) c. Manually destroy, call session.invalidate()

3. The scope of the request is once again, acting in a request

Creation time: When the request was made

Destruction time: when the request ends (that is, when the server responds to the request)

4. PageContext has the smallest scope and acts on the same jsp page (personal understanding of the following life cycle, there may be errors)

Create: when the jsp page is translated into a servlet and compiled and run

Destruction: When leaving the current jsp page
Article link: https://blog.csdn.net/cholg/article/details/95972862

Guess you like

Origin blog.csdn.net/m0_49194578/article/details/111933842