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;
}
}
struts2拦截器管理日志
猜你喜欢
转载自wawa129.iteye.com/blog/1747021
今日推荐
周排行