Click here to Skip to main content
11,584,622 members (68,628 online)
Rate this: bad
good
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
Comments
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--->http://stackoverflow.com/questions/2608452/how-to-keep-the-session-of-user-login

1 solution

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

Solution 1

Hello,

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();
      writer.println("===============");
      writer.println("The number of hits is: " + counter.incCounter());
      writer.println("===============");
 
      // Log the resulting string
      writer.flush();
      filterConfig.getServletContext().log(sw.getBuffer().toString());
      ...
      chain.doFilter(request, wrapper);
      ...
   }
}
This filter will be configured in web.xml as shown below
<filter id="filter_2">
    <filter-name>activitylogger</filter-name>
    <filter-class>com.yourcompany.filters.activity.HitCounterFilter</filter-class>
</filter>
Regards,
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 430
1 Sergey Alexandrovich Kryukov 367
2 Dave Kreskowiak 260
3 Richard Deeming 220
4 virusstorm 194
0 OriginalGriff 1,703
1 Sergey Alexandrovich Kryukov 1,267
2 Abhinav S 711
3 Dave Kreskowiak 687
4 Suvendu Shekhar Giri 568


Advertise | Privacy | Mobile
Web04 | 2.8.150707.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