JSP nine large built-in objects and four scopes

Source: Internet
Author: User

Request object Type Javax.servlet.ServletRequest Scope request

Response Response Object Type Javax.servlet.SrvletResponse scope Page

PageContext page Context object type Javax.servlet.jsp.PageContext Scope page

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 object Type Javax.lang.Object Scope page

Exception exception Object type javax.lang.Throwable Scope page

The "Exception" object represents the exception object that is generated by the JSP file runtime, which cannot be used directly in a generic JSP file, but only in a JSP file that uses "<%@ page iserrorpage=" true "%>".

First let's look at the effect:

Judging from the results shown, we can intuitively draw the conclusion that:

The variables in the request can span two pages before and after forward. But as soon as you refresh the page, they recalculate.

The variables in the application keep accumulating until you restart Tomcat, otherwise it will keep getting bigger.

If you put the variable in the PageContext, it means that its scope is page, its valid range is only in the current JSP page.

If you put the variable in the request, it means that it is scoped to request, and its valid range is the current demand period.

If you put the variable in the session, it means that it is scoped to the session, and its valid range is the current one.

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

Application The variables in the scope, they survive the longest, and if not manually deleted, they can be used all the time.

Unlike the three above, the variables in the application can be shared by all users. If user A's operation modifies the variable in application, the User B gets the modified value when he accesses it. This will not happen in any other scope, page, request,session are completely isolated, regardless of the modification will not affect other people's data.

JSP nine large built-in objects and four scopes

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.