The example of this article describes the Js+jsp method of implementing static page access count through the IMG tag invocation. Share to everyone for your reference, specific as follows:
Test page: test.html
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
Statistical procedure: pv.jsp:
Assume the deployment location is http://127.0.0.1:8080/EasyCMS/pv.jsp
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%> <% @page import= "java.io.*"%> <%
String path= "/opt/test.txt";
Writenumber (string.valueof (readnumber (path) +1), path);
%> <%=readnumber (path)%> <%! /** * Write Digital content * * @param number * @param filename * @return/public boolean writenumber (String
, String filename) {try {fileoutputstream fos = new FileOutputStream (filename);
OutputStreamWriter writer = new OutputStreamWriter (FOS);
Writer.write (number);
Writer.close ();
Fos.close ();
catch (IOException e) {e.printstacktrace ();
return false;
return true; /** * Read Digital content * * @param filename * @return/public int readnumber (String filename) {int Numbe
R = 0;
try {File File = new file (filename);
if (file.exists ()) {FileReader FR = new FileReader (file);
BufferedReader br = new BufferedReader (FR); String contents = Br.readline ();
if (contents!= null && contents.length () > 0) {contents = Contents.replaceall ("[^0-9]", "");
Number = integer.valueof (contents);
} br.close ();
Fr.close ();
} catch (IOException e) {e.printstacktrace ();
return number;
}%>
Basic idea:
Access static page, through the IMG tag specified SRC for Access statistics address, IMG tag to the statistical program to send a request to achieve statistics.
The statistics sample code uses files to record the number of accesses, and the actual project can record the database.
Key code:
Copy Code code as follows:
<script type= "Text/javascript" >document.write (" ");</script>
I hope this article will help you with JavaScript programming.