Struts2拦截器处理用户操作日志

public String intercept(ActionInvocation invocation) throws Exception {
   ActionContext ac = invocation.getInvocationContext();
   Object action = invocation.getAction();
   if (action instanceof LoginAction) {
      return invocation.invoke();
   }
    HttpServletRequest request = (HttpServletRequest) ac.get  (StrutsStatics.HTTP_REQUEST);
    //HttpServletResponse response = (HttpServletResponse) ac.get(StrutsStatics.HTTP_RESPONSE);
    HttpSession session = request.getSession();
    User user = (User) session.getAttribute("user_login");
    if (null == user) {
       if(log.isDebugEnabled()) {
          log.debug("redirect to login");
       }
       return Action.LOGIN;
    }

    ActionProxy proxy = invocation.getProxy();
    ActionConfig config = proxy.getConfig();
    log.info("[classname : "+config.getClassName() + "\tmethodname:" + config.getMethodName()+"]");
    return invocation.invoke();
} 

猜你喜欢

转载自jxdiamond.iteye.com/blog/1824756