Click here to Skip to main content
11,806,350 members (66,073 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: Java
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 at 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 at 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
0 Richard Deeming 205
1 Sergey Alexandrovich Kryukov 170
2 ppolymorphe 145
3 OriginalGriff 135
4 Abhinav S 120
0 OriginalGriff 3,330
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,905
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web03 | 2.8.151002.1 | Last Updated 24 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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