VB icon

Hit counter Servlet

Email
Submitted on: 1/2/2015 5:52:00 AM
By: Fiach Reid (from psc cd)  
Level: Advanced
User Rating: By 4 Users
Compatibility: Java (JDK 1.1)
Views: 1549
 
     This Servlet runs along side a Java-compatible Server, to provide a simple Hit counter, This technology can be demonstrated at www.eej.ulst.ac.uk/remote-viewer
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Hit counter Servlet
// Description:This Servlet runs along side a Java-compatible Server, to provide a simple Hit counter, This technology can be demonstrated at www.eej.ulst.ac.uk/remote-viewer
// By: Fiach Reid (from psc cd)
//**************************************

import java.servlet.*;
import java.io.*;
import java.util.Hashtable;
import java.util.Date;
/**
 * Counter Servlet
 *
 * This simple servlet uses server-side includes
 * to embed a hit counter in a page.
 * @author Fiach@eircom.net
 * @Demo at www.eej.ulst.ac.uk/remote-viewer
 * @version 1.2, 3/22/96
 */
public class CounterServlet extends GenericServlet {
 static int count = 0;
 static Date start = new Date();
 public void service(ServletRequest request, ServletResponse response) 
throws ServletException, IOException {
int temp;
response.setContentType("text/plain");
PrintStream ps = new PrintStream(response.getOutputStream());
synchronized (this) {
 temp = count++;
}
ps.println("This servlet has been accessed " + temp + " times since " 
 + start );
 }
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.