title: Visitor counter on Java http server
body: <p>Good evening,
  I found this really basic http server written in Java.</p>
  
  <pre><code>import java.io.IOException;
  import java.io.OutputStream;
  import java.net.InetSocketAddress;
  
  import com.sun.net.httpserver.HttpExchange;
  import com.sun.net.httpserver.HttpHandler;
  import com.sun.net.httpserver.HttpServer;
  
  public class Test {
  
  public static void main(String[] args) throws Exception {
      HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
      server.createContext("/test", new MyHandler());
      server.setExecutor(null); // creates a default executor
      server.start();
  }
  
  static class MyHandler implements HttpHandler {
      @Override
      public void handle(HttpExchange t) throws IOException {
          String response = "This is the response";
          t.sendResponseHeaders(200, response.length());
          OutputStream os = t.getResponseBody();
          os.write(response.getBytes());
          os.close();
      }
  }
  
  }
  </code></pre>
  
  <p>Now im trying to add a simple counter on the website which counts every visit there. I just found code which needs Java EE liabraries.
  Like this here:</p>
  
  <pre><code>import java.io.*;
  import java.sql.Date;
  import java.util.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  public class PageHitCounter extends HttpServlet{
  
  private int hitCount; 
  
  public void init() 
  { 
   // Reset hit counter.
   hitCount = 0;
   } 
  
  public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
          throws ServletException, IOException
   {
    // Set response content type
    response.setContentType("text/html");
    // This method executes whenever the servlet is hit 
    // increment hitCount 
    hitCount++; 
    PrintWriter out = response.getWriter();
    String title = "Total Number of Hits";
    String docType =
    "&lt;!doctype html public \"-//w3c//dtd html 4.0 " +
    "transitional//en\"&gt;\n";
    out.println(docType +
      "&lt;html&gt;\n" +
      "&lt;head&gt;&lt;title&gt;" + title + "&lt;/title&gt;&lt;/head&gt;\n" +
      "&lt;body bgcolor=\"#f0f0f0\"&gt;\n" +
      "&lt;h1 align=\"center\"&gt;" + title + "&lt;/h1&gt;\n" +
      "&lt;h2 align=\"center\"&gt;" + hitCount + "&lt;/h2&gt;\n" +
      "&lt;/body&gt;&lt;/html&gt;");
  
    }
     public void destroy() 
    { 
    // This is optional step but if you like you
    // can write hitCount value in your database.
    } 
    } 
  </code></pre>
  
  <p>Is it possible to write this with the Java SE Development Kit? And how?</p>