<body> <%!int Count; %> <%int count2=0%> Output declaration count:<%=count++%> <br> Output script count2:<%=count2++%> <br > </body>
Each time the JSP page is refreshed the corresponding output results
Count incremented by 1 per refresh
Count2 Every time the refresh is not changed
Analysis:
Because count is a variable declared in a JSP, when the JSP is compiled into a servlet, cout is a member variable of the Servlet object, and the Servlet object is destroyed by invoking the Destroy () method based on the servlet lifecycle when the Web is closed. So each refresh will increase by 1;
and count2 the variable declared in the JSP script is equivalent to the JSP compiled into a servlet, will be compiled into the Servlet-jspservice method executable code is the method's local variables, meaning that the life cycle of the variable is only before and after the method call, so after each refresh The Count2 value is reinitialized to 0;
<body> <%!int Count; %> <%int count2=0; %> output declaration when count:<%=count++%> <br> output script count:<%=count2++%> <br> </body>
JSP: JSP declaration and JSP script <%! int count=0;%> with <% int count=0;%>