CountVisitorsServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 * This Servlet counts and prints the number of visitors.
 
 @author Sofoklis Stouraitis
 
 */
public class CountVisitorsServlet extends HttpServlet {

  /*
   * The Integer who counts the visitors.
   */
  private int visitorsCounter = 0;

  /**
   * Handles HTTP GET requests.
   
   @param request
   *            the request object
   @param response
   *            the response object
   
   @throws IOException
   *             if an input or output error is detected when the servlet
   *             handles the GET request
   @throws ServletException
   *             if the request for the GET could not be handled
   */
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

    response.setContentType("text/html; charset=ISO-8859-7");
    PrintWriter out = new PrintWriter(response.getWriter()true);

    try {
      out.println("<html>");
      out.println("<head>");
      out.println("  <title>CountVisitorsServlet</title>");
      out.println("    <meta http-equiv='Content-Type' content='text/html; charset=windows-1253'>");
      out.println("</head>");
      out.println("  <bodybgcolor='#FFFF99'>");
      out.println("  <h1>CountVisitorsServlet is running...</h1><br>");
      out.println("Αυτή την σελίδα την έχουν δει <b>" + ++visitorsCounter
          "</b> επισκέπτες!<br>");
      out.println("  </body>");
      out.println("</html>");

    catch (Exception ex) {
      out.println("Exception: " + ex.getMessage());
      out.println("  </body>");
      out.println("</html>");
    }
  }
}// End of class