JSP: Using implicit objects to count the number of sites visited
jsp
隐式对象
赵振江
implicitly-Object application objects
Use an implicit object to write a JSP program for a Web site that counts the number of visits to that site.
One situation is: According to the customer statistics (according to the browser statistics, a browser if access to the site, even if a visit, in other words, if the browser refresh multiple sites, but also a visit);
Another scenario: refresh the page once, even if it is a single visit.
Requires an implicit object to be implemented.
counter.jsp
<%@ page language="java" import="java.util.*" pageencoding= "UTF-8"%><%StringPath =Request. Getcontextpath ();StringBasePath =Request. Getscheme () +"://"+Request. getServerName () +":"+Request. Getserverport () +path+"/";%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" ><html><head ><base href=" <%=basePath%> "> <title>My JSP ' counter.jsp ' starting page</title> <meta http-equiv =" pragma " content = "No-cache" ; <meta http-equiv =" Cache-control " content = "No-cache" ; <meta http-equiv =" expires " content = "0" ; <meta http-equiv =" keywords " content = "Keyword1,keyword2,keyword3" ; <meta http-equiv="description" content="This is my page"> <!--<link rel= "stylesheet" type= "Text/css" href= "Styles.css" > - </head> <%if(Application.getattribute ("Counter")==NULL){StringCounter="0"; Application.setattribute ("Counter", counter); }Else{intCount=integer.valueof ((String) Application.getattribute ("Counter"). Intvalue (); count++; Application.setattribute ("Counter", count+""); }%> <body> This is my JSP page. <br> This site has been visited: <%=application.getattribute ("Counter")%>times. </body> </html>
JSP: Using implicit objects to count the number of sites visited