如何在java中维护用户logg [英] how maintain user logg in java

查看:48
本文介绍了如何在java中维护用户logg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何维护用户日志,例如用户点击数据库中记录的信息................ pLz帮助我....... !!

how to maintain user log like where user clicked that information recorded in data base................pLz help me.......!!

推荐答案

您好,



Java Servlet规范版本2.3引入了一种新的组件类型,称为过滤器。过滤器动态拦截请求和响应,以转换或使用请求或响应中包含的信息。过滤器通常不会自己创建响应,而是提供可以附加到任何类型的servlet或JSP页面的通用函数。

您可以编写自己的过滤器来实现这一目标。这是一个直接取自记录servlet访问权限的文档的小例子。

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);
      ...
   }
}



此过滤器将在 web.xml中配置如下所示

<filter id="filter_2">
    <filter-name>activitylogger</filter-name>
    <filter-class>com.yourcompany.filters.activity.HitCounterFilter</filter-class>
</filter>



问候,


Regards,


这篇关于如何在java中维护用户logg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆