struts2拦截器管理日志

1:struts配置
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="prot" extends="json-default">
<interceptors>
<interceptor name="protInterceptor"
class="com.home.cn.web.interceptor.ProtInterceptor">
</interceptor>
</interceptors>
<action name="protAction" class="com.asia.home.cn.web.prot.ProtAction">
<result name="list" type="redirect">/main/prot/list.jsp</result>
<result name="csList">/main/cs/list.jsp</result>
<result name="csEdit">/main/cs/edit.jsp</result>
<result name="csInfo">/main/cs/info.jsp</result>
<result name="adInfo">/main/ad/protinfo.jsp</result>
<result name="logout">/logout.html</result>
<result type="json"/>
<interceptor-ref name="protInterceptor">
<param name="includeMethods">ad_edit,upStatus,editByStatus,change_att,delProt</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"/>
</action>
</package>
</struts>


2:拦截器类
package com.home.cn.web.interceptor;

import java.util.Date;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.home.cn.contract.entity.SysLogInfo;
import com.home.cn.contract.entity.user.Exiuser;
import com.home.cn.services.log.ISysLogService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

public class ProtInterceptor extends MethodFilterInterceptor {
SysLogInfo logInfo = SysLogInfo.getInstance();
private ISysLogService logService;

@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
String returnValue = invocation.invoke();
// 取得请求相关的ActionContext实例
ActionContext ctx = invocation.getInvocationContext();
HttpServletRequest request = ServletActionContext.getRequest();
Map session = ctx.getSession();
String flowNo = (String)request.getAttribute("flowNO"); //流水号
String operatorMessage = (String)request.getAttribute("operatorMessage"); //操作系统
String vMessage = (String)request.getAttribute("vMessage"); //是否重复
String operatorStatus = (String)request.getAttribute("operatorStatus"); //操作状态
Exiuser user = (Exiuser) session.get("USER_INFO");
logInfo.setFlowNo(flowNo);
logInfo.setMessage(operatorMessage);
logInfo.setStatus(operatorStatus);
logInfo.setUserName(user.getFsName());
logInfo.setCreateTime(new Date());
if(!"请不要重复提交!".equals(vMessage)&&operatorStatus!=null){
logService.save(logInfo);
}
return returnValue;
}

@Override
public Set<String> getExcludeMethodsSet() {
// TODO Auto-generated method stub
return super.getExcludeMethodsSet();
}

@Override
public Set<String> getIncludeMethodsSet() {
// TODO Auto-generated method stub
return super.getIncludeMethodsSet();
}

public void setLogService(ISysLogService logService) {
this.logService = logService;
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值