JSP: Using implicit objects to count the number of sites visited

Source: Internet
Author: User

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

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.