Four scopes for a servlet

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.