Get the App
SLTechnology News&Howtos  ›  Development  › 

Introduction to the four scopes of JavaWeb

Shulou Source: shulou.com Published: 2022-06-03 18:48:40 10月01日 Update

This article mainly explains the "introduction of the four scopes of JavaWeb". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the introduction of the four scopes of JavaWeb.

1. PageContext domain:

The scope is the entire JSP page, the smallest of the four scopes; the life cycle starts when a request to JSP is made and is destroyed when the response ends.

Second, the ServletRequest domain:

The scope is the entire request chain (request forwarding also exists); the life cycle is created by the server before the service method call, passing in the service method. The whole request ends and request's life ends.

3. HttpSessiondomain:

The scope of action is a conversation. The life cycle is when the request.getSession () method is called for the first time, the server checks to see if there is already a corresponding session, and if not, creates a session in memory and returns. When the session is not used for a period of time (the default is 30 minutes), the server destroys the session. If the server shuts down abnormally (forcibly shut down), the session that has not expired will also be destroyed. If you call invalidate () provided by session, you can destroy the session immediately.

Note: when the server shuts down normally and then starts, the Session object will be passivated and activated. At the same time, if the server passivation time is within the default destruction time of session, then session still exists after activation. Otherwise, Session does not exist. If JavaBean data is passivated by session and Serializable is not realized, it will disappear when Session is activated.

IV. ServletContext domain:

The scope of action is the entire Web application. When the Web application is loaded into the container, a ServletContext object representing the entire web application is created, and when the server is shut down or the Web application is removed, the ServletContext object is destroyed.

In short, the four scopes of JavaWeb can be summarized as follows:

PageContext: valid on this page, but invalid if you jump out of the page

ServletRequest: cross-page function, generally used for form submission, etc.

HttpSession: use during a certain session

ServletContext: always valid, invalidated after shutting down the server.

Thank you for your reading. The above is the content of "introduction to the four scopes of JavaWeb". After the study of this article, I believe you have a deeper understanding of the introduction of the four scopes of JavaWeb, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Role server service life scope application cycle object method time follow page learning effective content is in minimum representative memory at the same time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Linux Redmi Docker Huawei