#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    1
    Rep Power
    0

    Question simple jsp counter


    I am unfamiliar with jsp and need a simple hit counter that writes the number of hits to a text file. No worries about unique IPs or displaying the count on the page. Using Unix/Apache/Tomcat. No frills necessary...just a number in a text file. Thanks.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    3
    Rep Power
    0
    Here is a sample.
    PHP Code:
    <%@page language="java" import="java.io.*"%>
    <%
    java.io.File counterFile;
    BufferedReader counterInput;
    BufferedWriter counterOutput;
    String counterText "";
    String tempText "";
    int intCounter 0;

    try {
        
    counterFile = new java.io.File("/path_to_counter_file/counter.txt");
        
    counterInput = new BufferedReader(new FileReader(counterFile));
        while (
    counterInput.ready()) {
            
    tempText counterInput.readLine();
            if (
    tempText == null) {
                break;
            } else {
                
    counterText += tempText;
            }
        }
        
    counterInput.close();

        
    intCounter Integer.parseInt(counterText);
        
    intCounter++;
        
        
    counterOutput = new BufferedWriter(new FileWriter(counterFile));
        
    counterOutput.write(""+intCounter);
        
    counterOutput.flush();
        
    counterOutput.close();
    } catch (
    Exception e) {
        
    out.write("Error on countering: "+e);
    }
    %> 

IMN logo majestic logo threadwatch logo seochat tools logo