Scope of the JSP-scope (Web Foundation learning Note v)

Source: Internet
Author: User

scope of the JSP (scope)

Objects in JSP pages, including user-created objects such as JavaBean, have a range attribute, which is also called scope. The scope defines the time at which these objects can be accessed in which JSP page. For example, session objects can be accessed on multiple pages during a session. Application objects can be accessed throughout the entire life cycle of the Web application. In JSP, there are 4 scopes. That's the page range, request range, session range, and application range.

Page Range

An object with a page range is bound to a Javax.servlet.jsp.PageContext object, which is accessible only in the page where the object is created. You can call the GetAttribute () method of the PageContext object to access this range of objects, or you can use the SetAttribute method to set the object or property of the range. Page-scoped object, which is created every time the client requests a JSP page, and the object or property is deleted after the page sends a response to the client or the request is forwarded.

Request Range

The object with the request scope is bound to the Javax.servlet.http.HttpServletRequest object, and you can call the Set/getattribute method of the request built-in object to set or access the object of the range. You can also access this range of objects by calling the forward method to another page or using the pages included in the include. But objects within this range are valid only for the same request, which means that objects within this range cannot be shared between different requests.

Session Range

Objects with a session scope are bound to the Javax.servlet.http.HttpSession object, and you can call the Set/getattribute method of the session's built-in object to access objects with this range. Objects of this scope are for sessions, they can only be accessed during the same session, and such objects are not shared during different sessions.

Application Range

Objects with application scopes are bound to javax.servlet.ServletContext objects, and you can call the Set/getattribute method of application built-in objects to access objects with this range. All pages can access this range of objects while the Web app is running.

Scope of the JSP-scope (Web Foundation learning Note v)

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.