action 过滤器: 如:package com.haople.interceptor;import org.haopeng.util.SessionTools;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.Interceptor;/** *此拦截器针对action下所有的方法进行拦截 * @author Administrator * */public class ActionInterceptorForMember implements Interceptor { public String intercept(ActionInvocation invocation) throws Exception { if(SessionTools.getSessionMember() != null && SessionTools.getSessionMember().getMemberId()>0){ return invocation.invoke(); } else{ return "login"; } } public void destroy() { // TODO Auto-generated method stub } public void init() { // TODO Auto-generated method stub }}方法过滤器: 如:package com.haople.interceptor;import org.haopeng.util.SessionTools;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;/** *此拦截器可以针对action中指定的方法进行拦截 * @author Administrator * */public class MethodInterceptorForMember extends MethodFilterInterceptor { protected String doIntercept(ActionInvocation invocation) throws Exception { //如果会员已经登陆则执行相应的action if(SessionTools.getSessionMember() != null && SessionTools.getSessionMember().getMemberId()>0){ return invocation.invoke(); } else{ return "login"; } }}过滤器需要配置:拦截器一般定义在struts.xml(stuts配置文件 login,ddd aaa,bbb ... ) 在需要调用的action中引用:拦截器的中常用的方法: 1. HttpServletRequest request=ServletActionContext.getRequest(); String logIp=request.getRemoteAddr(); //获取请求的ip地址 2. String methodName = actionInvocation.getProxy().getMethod(); //获取当前执行的方法名 3. String ActionName=actionInvocation.getProxy().getActionName(); //获取当前执行的action类名(不包含包名) 4. LoginAction loginAction=(LoginAction)invocation.getAction(); //获取当前执行的action对象 5. ActionContext act=invocation.getInvocationContext(); Map session=act.getSession(); //获取session 6. HttpServletRequest request=ServletActionContext.getRequest(); //获取request