Differentiation of attributes of JSP usebean Scope

Source: Internet
Author: User

The scope attribute is used to specifyStorage domain rangeThe value can only be one of the four values: Page, request, session, and application. The default value is page.

I can test the following code:

Date. jsp

---------------------------------------------------------

<JSP: usebean id = "currentdate" class = "Java. util. Date" Scope = "request"/>
<% = Currentdate. tostring () %>

 

Test results:

1. When scope = application, we browse date. jsp, and the system time is displayed. However, no matter how we refresh it, open another browser, or even change the server, the display time remains the same, it is the original time (that is, the system time obtained when bean was just created ), because scope = application, the JavaBean instance has only one copy in the memory. At this time, as long as the Web service is not restarted, the output will not change.

2. When scope = session, browsing date. jsp will not change during refresh. However, when we re-open a browser, that is, a new session, the system will create a JavaBean instance again to get the current system time, then the correct time will be obtained. Similarly, if you refresh the newly opened page again, the display will not change.

3. When scope = page/request, the page will be refreshed continuously to get the current system time.

 

Meanings and functions of each set value of the scope attribute:

(1) page indicatesJavaBean Instance ObjectStored inPagecontext objectIs effective on the current JSP page.

(2) request indicates that the JavaBean instance object is stored in the servletrequest object. the JavaBean object stored in the request object can be accessed by all servlets and JSP pages in the same request.

(3) session indicates that the JavaBean instance object is stored in the httpsession object. the JavaBean object stored in the httpsession object can be accessed by all servlets and JSP pages belonging to the same session, this setting requires that the current JSP page supports session, that is, the session attribute of the page command is not set to false. That isA specific userValid: An http session.

(4) application indicates that the JavaBean instance object is stored in the servletcontext object. the JavaBean object stored in the servletcontext object can be accessed by all servlets and JSP pages in the same web application. That isAll usersCan be used.

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.