Servlet Request Listener : Do Get Do Post « Servlets « Java






Servlet Request Listener

 
import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletRequest;

public class ReqListener implements ServletRequestListener {

  private static long reqCount;

  public void requestInitialized(ServletRequestEvent sre) {

    ServletContext context = sre.getServletContext();
    ServletRequest request = sre.getServletRequest();

    synchronized (context) {
      context
          .log("Request for "
              + (request instanceof HttpServletRequest ? ((HttpServletRequest) request)
                  .getRequestURI()
                  : "Unknown") + "; Count=" + ++reqCount);
    }

  }

  public void requestDestroyed(ServletRequestEvent sre) {

  }

}

           
         
  








Related examples in the same category

1.Simple servlet: Copyright
2.Print various CGI variables that have been requested by the servlet
3.Print all header information available from the client
4.Request header viewer
5.Request binder
6.Request display
7.Client auto refresh
8.Get Request Parameters in a Servlet