The scope specifies the validity period of the variable, and the servlet has four scope objects, which only say three:
A. Request scope:
1. Scope: Refers to the entire process of returning a response from an HTTP request to the end of the server processing. You may use forward to jump through multiple JSP pages in this process, and you can use this variable in these pages.
2.request Object generation: The request generates an object each time it arrives at the server side;
Two. Session Scope:
1. Scope: Current session
1) Current session: Refers to the process of opening a browser from the user to the user to close the browser. This process may contain multiple request responses. In other words, as long as the user does not close the browser, the server has a way to know that these requests are initiated by a person, the whole process is called a session
The server can set up a corresponding container object for each client, that is, the session, the server to save the client's data;
2.session Object generation: Call Request.getsession () method, note there are two getsession () methods, one is a Boolean parameter method;
3.session Destruction
1) session timeout;
2) After the client shuts down, it can no longer access the session corresponding to the client, it will be destroyed after the timeout;
3) Call session. Invalidate ();
Three. ServletContext () Application Context Object
1. Scope of action: the entire application
1) Entire application: refers to starting from the application, to the end of the application. We did not say "boot from server to server shutdown" because a server might deploy multiple applications, and of course you shut down the server and shut down all of the applications.
2. Object generation: All deployed Web apps are mounted when the server starts, and a ServletContext object is created for each app;
3. Destroy: The ServletContext object will be destroyed when the server shuts down;
4. Features:
1) Each app will only create a unique, common ServletContext object;
2) All clients share the same ServletContext object when accessing the server;
5. Scene:
ServletContext objects are generally used when sharing data among multiple clients;
Four scopes for a servlet