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();
}
Struts2拦截器处理用户操作日志
最新推荐文章于 2017-03-19 12:10:11 发布
本文介绍了一个基于Struts框架的自定义拦截器实现过程。该拦截器主要用于验证用户登录状态,通过获取Session中的用户信息来判断是否已登录,并根据不同情况返回相应的操作结果。

227

被折叠的 条评论
为什么被折叠?



