About nine built-in jsp objects and four scopes, and nine jsp objects

Source: Internet
Author: User

About nine built-in jsp objects and four scopes, and nine jsp objects

Request Request object type javax. servlet. ServletRequest scope request

Response object type javax. servlet. SrvletResponse scope Page

PageContext Page Context object type javax. servlet. jsp. PageContext scope Page

Session Session object type javax. servlet. http. HttpSession scope session

Application Application Object Type javax. servlet. ServletContext Scope application

Out output object type javax. servlet. jsp. JspWriter scope Page

Config configuration object type javax. servlet. ServletConfig scope Page

Page Page Object Type javax. lang. Object scope page

Exception object type javax. lang. Throwable scope page

The "exception" object represents the exception object generated when the JSP file is running. This object cannot be directly used in common JSP files, it can only be used in JSP files that use "<% @ page isErrorPage =" true "%>.

Scope

Let's take a look at the effect:

The general process is like this. When we access index. jsp, we accumulate the variables in pageContext, request, session, and application scopes respectively. (Of course, first determine whether the variable exists. If the variable does not exist, initialize the variable to 1 ). After the calculation is complete, execute forward from index. jsp to test. jsp. Accumulate again in test. jsp, and then display the four integers.

From the displayed results, we can intuitively draw a conclusion:

The variables in the page cannot be passed from index. jsp to test. jsp. As long as the page jumps, they will disappear.

The variables in the request can span the two pages before and after the forward. However, you only need to refresh the page, and they will recalculate it.

The variables in the session and application have been accumulating and there is no difference at first. As long as you close the browser and restart the browser to access this page, the variables in the session will be recalculated.

The variables in the application keep accumulating. Unless you restart tomcat, it will keep increasing.

The scope specifies the validity period of the variable.

If you put the variable in pageContext, it indicates that its scope is page, and its valid range is only in the current jsp page.

You can use this variable from placing it in pageContext to the end of the jsp page.

If you put the variable in the request, it indicates that its scope is request, and its valid range is the current request cycle.

The request cycle refers to the whole process from initiating an http request to processing the server and returning a response. In this process, you may use the forward method to jump to multiple jsp pages. You can use this variable in these pages.

If the variable is put into the session, it indicates that its scope is session, and its valid range is the current session.

The current session refers to the process from when the user opens the browser to when the user closes the browser. This process may contain multiple request responses. That is to say, as long as the user is not in the browser, the server can know that these requests are initiated by a person. The whole process is called a session and put into the session variable, it can be used in all requests of the current session.

If you put the variable in the application, it indicates that its scope is application, and its effective scope is the entire application.

The entire application starts from the application and ends with the application. We didn't say "starting from the server to shutting down the server" because one server may deploy multiple applications. Of course, if you close the server, all the above applications will be shut down.

Variables in the application scope have the longest survival time. They can be used without manual deletion.

Different from the preceding three, the variables in the application can be shared by all users. If user a's operations modify the variables in the application, user B obtains the modified value during access. This will not happen in other scopes. pages, requests, and sessions are completely isolated, and data of others will not be affected no matter how modified.

The nine built-in jsp objects and the Four Scopes mentioned above are all the content shared by Alibaba Cloud xiaobian. I hope to give you a reference and support for the customer's home.

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.