Because the application object is used to complete the accumulative function, when
(1) Redeploy the current Wen Application
(2) restart the Tomcat server
The counter starts counting again.
The jsp code is as follows:
Copy codeThe Code is as follows:
<% @ Page language = "java" contentType = "text/html; charset = UTF-8"
PageEncoding = "UTF-8" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> Insert title here </title>
</Head>
<Body>
<%
// Check whether the parameter count is saved in the application object.
// If NO, add a parameter named count in the application object.
If (application. getAttribute ("count") = null ){
Application. setAttribute ("count", new Integer (0 ));
}
Integer count = (Integer) application. getAttribute ("count ");
// Use the application object to read the value of the count parameter, and then accumulate 1 based on the original value
Application. setAttribute ("count", new Integer (count. intValue () + 1 ));
%>
<H2>
<! -- Output the value corresponding to the accumulated count parameter -->
Welcome to visit. This page has been accessed <font color = "# ff0000"> <% = application. getAttribute ("count") %> </font> times ....
</H2>
</Body>
</Html>
Enter http: // localhost: 8888/WebDemo/count. jsp in the browser.
Include the count. jsp file in the jsp file to be counted.
Copy codeThe Code is as follows:
<% @ Include file = "count. jsp" %>