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.