Js+jsp method of implementing static page Access Count via img tag _javascript tips

Source: Internet
Author: User

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.

Related Article

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.