Hit Counter


Simple program to demonstrate accessing a servlet in Apache Tomcat Server

Hit counter program

 

import javax.servlet.http.*; 

import javax.servlet.*; 

import java.io.*; 

 

public class HitCounter extends HttpServlet

{ 

 

     private int counter = 0;

     public void doGet(HttpServletRequest req,HttpServletResponse res)

throws ServletException, IOException 

     { 

          //setting the content type

          res.setContentType("text/html");

 

          //create the stream to write the data 

          PrintWriter pw=res.getWriter();

            

          counter++;

         

          //writing html in the stream 

          pw.println("<html><body>"); 

          pw.println("<h2>Hit Count = "+counter+"</h2>"); 

          pw.println("</body></html>"); 

         

          //closing the stream

          pw.close(); 

     }

}   

 

 

 

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu