Click here to Skip to main content
13,598,013 members
Rate this:
Please Sign up or sign in to vote.
See more:
how to maintain user log like where user clicked that information recorded in data base................pLz help me.......!!
Posted 10-Feb-13 21:59pm
Richard MacCutchan 11-Feb-13 4:24am
You need to provide a lot more detail about your problem. Are you trying to log every action on the system, or just the ones in this application?
DalliaF 8-Mar-13 2:43am
there is an example on this site--->

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


The Java Servlet specification version 2.3 introduced a new component type, called a filter. A filter dynamically intercepts requests and responses to transform or use the information contained in the requests or responses. Filters typically do not themselves create responses, but instead provide universal functions that can be "attached" to any type of servlet or JSP page.
You can write your own filter to achieve this. Here is a small example directly taken from documentation which logs the servlet access.
public final class HitCounterFilter implements Filter
   private FilterConfig filterConfig = null;

   public void init(FilterConfig filterConfig) throws ServletException
      this.filterConfig = filterConfig;

   public void destroy()
      this.filterConfig = null;

   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
      StringWriter sw = null;
      PrintWriter writer = null;
      if (filterConfig == null) return;

      sw = new StringWriter();
      writer = new PrintWriter(sw);
      Counter counter = (Counter) filterConfig.getServletContext().getAttribute("hitCounter");
      writer.println("The number of hits is: " + counter.incCounter());

      // Log the resulting string
      chain.doFilter(request, wrapper);

This filter will be configured in web.xml as shown below
<filter id="filter_2">


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web03-2016 | 2.8.180621.3 | Last Updated 24 Mar 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100