ReqListener.java Source code

Java tutorial

Introduction

Here is the source code for ReqListener.java

Source

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) {

    }

}