功能:
   用户登陆进来,添加,修改,删除,查看得功能记录并在jsp里显示出来谁写过共享一下。或者说一下思路谢谢了 

解决方案 »

  1.   

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpSession;
    import org.apache.log4j.MDC;public class LoggerFilter implements Filter {
        
        public void doFilter(ServletRequest request, ServletResponse response,
                FilterChain chain) throws IOException, ServletException {
            
            // Retrieves the session object from the current request.
            HttpSession session = ((HttpServletRequest)request).getSession();
            
            // Put the username into the diagnostic context.
            // Use %X{username} in the layout pattern to include this information.
            MDC.put("username", session.getAttribute("username"));
            
            // Continue processing the rest of the filter chain.
            chain.doFilter(request, response);
            
            // Remove the username from the diagnostic context.
            MDC.remove("username");
        }
        ...
    }