Difference instance of Application Session Request in JSP

Source: Internet
Author: User

Put. jsp

<% @ Page contenttype = "text/html; charset = GBK" Language = "Java" errorpage = "" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <HTML xmlns =" http://www.w3.org/1999/xhtml "> 


Get. jsp

<% @ Page contenttype = "text/html; charset = GBK" Language = "Java" errorpage = "" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <HTML xmlns =" http://www.w3.org/1999/xhtml "> 

Refresh put in different browser processes. JSP page, no matter in which browser process access get. the JSP page must get a consistent value, because the counter scope is under the application, and if you close the browser, the value obtained after re-opening the put or get page is the value of the last access because the application has not been destroyed. At the same time, note that if you access the put page in different browsers (regardless of whether the browser is closed again or not), the value is consistent (next visit"
I "+ 1), because here JSP is converted to servlet (and only converted once), there is only one instance object on the backend of the server, therefore, the "I" value accessed by everyone is the same, until the server destroys the servlet, or restarts the server to redeploy the server application, the "I" is reset to 0.


If the application in the Code is changed to session (a connection between the server and the browser exists only when the browser is not closed), if the browser process is not closed, access get in that browser process. on the JSP page, we get the session in that browser. setattribute ("counter", String. valueof (++ I); because the counter scope is under the session, different browser processes have different sessions. If the browser is closed, the session is destroyed. The value of the saved counter variable becomes null.


If the application in the Code is changed to request, when and where to access the get page, the result must be null. Because when the get page is accessed again, the request is different. getattribute ("counter") must be empty.

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.