Struts2拦截器属性excludeMethods、includeMethods配置无效之解决方法
来源:互联网 发布:北京美特软件 编辑:程序博客网 时间:2024/06/05 08:35
在配置struts2 拦截器属性excludeMethods、includeMethods进行方法过滤时发现不起作用。
经过查看书籍之后发现,要想使方法过滤配置起作用,拦截器需要继承MethodFilterInterceptor类。MethodFilterInterceptor类是AbstractInterceptor的子类,其源代码如下:
public abstract class MethodFilterInterceptor extends AbstractInterceptor { protected transient Logger log = LoggerFactory.getLogger(getClass()); protected Set<String> excludeMethods = Collections.emptySet(); protected Set<String> includeMethods = Collections.emptySet(); public void setExcludeMethods(String excludeMethods) { this.excludeMethods = TextParseUtil.commaDelimitedStringToSet(excludeMethods); } public Set<String> getExcludeMethodsSet() { return excludeMethods; } public void setIncludeMethods(String includeMethods) { this.includeMethods = TextParseUtil.commaDelimitedStringToSet(includeMethods); } public Set<String> getIncludeMethodsSet() { return includeMethods; } @Override public String intercept(ActionInvocation invocation) throws Exception { if (applyInterceptor(invocation)) { return doIntercept(invocation); } return invocation.invoke(); } protected boolean applyInterceptor(ActionInvocation invocation) { String method = invocation.getProxy().getMethod(); // ValidationInterceptor boolean applyMethod = MethodFilterInterceptorUtil.applyMethod(excludeMethods, includeMethods, method); if (log.isDebugEnabled()) { if (!applyMethod) { log.debug("Skipping Interceptor... Method [" + method + "] found in exclude list."); } } return applyMethod; } /** * Subclasses must override to implement the interceptor logic. * * @param invocation the action invocation * @return the result of invocation * @throws Exception */ protected abstract String doIntercept(ActionInvocation invocation) throws Exception; }
只需要实现该类中的
protected abstract String doIntercept(ActionInvocation invocation) throws Exception即可。
样例代码:
package cua.survey.interceptor;import java.util.Map;import com.opensymphony.xwork2.Action;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;public class LoginInterceptor extends MethodFilterInterceptor{private static final long serialVersionUID = 1L;protected String doIntercept(ActionInvocation action) throws Exception {Map<String, Object> session = ActionContext.getContext().getSession();String user = (String)session.get("user");if(user != null && !"".equals(user)){return action.invoke();}else{session.put("error", "your user or pwd is error, please login again...");return Action.LOGIN;}}}
实现之后拦截器属性excludeMethods、includeMethods就可以起到作用了。
- Struts2拦截器属性excludeMethods、includeMethods配置无效之解决方法
- Struts2拦截器属性excludeMethods、includeMethods配置无效之解决方法
- Struts2拦截器属性excludeMethods、includeMethods配置无效的原因
- struts2中关于拦截器Interceptor中的excludeMethods和includeMethods
- struts2中方法拦截器(Interceptor)的中的excludeMethods与includeMethods的理解
- struts2中关于拦截器Interceptor中的excludeMethods和includeMethods的理解
- struts2中方法拦截器(Interceptor)的中的excludeMethods与includeMethods的理解
- struts拦截器includeMethods或excludeMethods没起作用
- Struts2的拦截器笔记--excludeMethods
- Struts2的Interceptor中使用includeMethods 和 excludeMethods
- Struts2拦截器配置
- struts2 拦截器配置
- Struts2配置拦截器
- 配置struts2拦截器
- Struts2拦截器配置
- struts2 拦截器配置
- Struts2拦截器配置
- struts2拦截器配置
- [Tomcat6.0源码]项目的部署
- mysql command line client 打不开(闪一下消失)的解决办法
- STM32的I2C难点(值得慢慢研究)
- 12个固态硬盘优化技巧,延长固态硬盘使用寿命
- pthread_cancel
- Struts2拦截器属性excludeMethods、includeMethods配置无效之解决方法
- Linux操作系统目录配置标准FHS详细介绍
- IOS开发之UIView动画效果的实现
- 查看iptables状态-重启
- java中枚举类型的使用
- 英国彩票基金会拨款1200万英镑林肯城堡
- Oracle ORA-01747: invalid user.table.column, table.column, or column specification
- Delphi 支持通配符删除文件!
- 英国国家彩票拨款320万资助北爱特殊年轻人项目