Struts2使用MethodFilterInterceptor来实现方法拦截器
来源:互联网 发布:js跨域方法 编辑:程序博客网 时间:2024/06/13 00:01
如果要对action类的指定方法进行拦截,拦截器的类需要继承MethodFilterInterceptor
将AbstractInterceptor方法先隐藏
package mypro;
import java.util.Map;
import java.util.Set;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsStatics;
public class loginInterceptor extends MethodFilterInterceptor{
/*public String intercept(ActionInvocation actionInvocation) throws Exception
{
Map session = actionInvocation.getInvocationContext().getSession();
if(null == session.get("email")){
return "unlogin";
}
return actionInvocation.invoke();
}*/
@Override
public void setExcludeMethods(String excludeMethods) {
super.setExcludeMethods(excludeMethods);
}
@Override
public Set<String> getExcludeMethodsSet() {
return super.getExcludeMethodsSet();
}
@Override
protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
Set<String> ss = getExcludeMethodsSet();
String actionname = actionInvocation.getProxy().getActionName().toString();
for (String s : ss) {
if (actionname.equals(s)) {
return actionInvocation.invoke();
}
}
Map session = actionInvocation.getInvocationContext().getSession();
if (null == session.get("email")) {
return "unlogin";
}
return actionInvocation.invoke();
}
}
在struts.xml action中配置要拦截的方法和不需要拦截的方法
<interceptors>
<interceptor name="loginCheck" class="mypro.loginInterceptor" />
<interceptor-stack name="myStack">
<interceptor-ref name="loginCheck">
<param name="excludeMethods">handleLogin,login</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="myStack"></default-interceptor-ref>
<global-results>
<result name="unlogin">/templets/login.jsp</result>
<result name="error">/error.jsp</result>
</global-results>
- Struts2使用MethodFilterInterceptor来实现方法拦截器
- Struts2使用MethodFilterInterceptor来实现方法拦截器
- Struts2——MethodFilterInterceptor--方法拦截器
- struts2的拦截器(5):继承MethodFilterInterceptor抽象类实现拦截方法的拦截器
- S2SH开发中拦截器的方法拦截的实现 MethodFilterInterceptor?
- Struts 2 methodfilterinterceptor--拦截方法的拦截器
- Struts 2 methodfilterinterceptor--拦截方法的拦截器
- Struts 2 methodfilterinterceptor--拦截方法的拦截器
- SSH-Struts2简单的自定义拦截器MethodFilterInterceptor
- struts2使用Interceptor接口来实现拦截器
- Struts2-MethodFilterInterceptor
- 【Struts2】:拦截器实现方法过滤
- struts2使用AbstractInterceptor实现拦截器
- struts2使用AbstractInterceptor实现拦截器
- struts2方法拦截器
- struts2 拦截器实现
- struts2拦截器使用
- struts2使用拦截器
- 汉诺塔问题
- Ubuntu16.04 opencv3 python2.7 caffe(CPU_ONLY)
- spark1.x-sql-架构原理
- centos7.0中安装androidstudio 启动模拟器出问题,原因是32库引起的
- 浏览器中在线预览pdf文件(不使用插件)
- Struts2使用MethodFilterInterceptor来实现方法拦截器
- Android平台Native开发与JNI机制详解
- Android通过wifi连接手机(不需要root)
- 如何对一个算法进行复杂度分析
- 事务的隔离级别,加锁的细节,以及两者之间的关系。 同时也说明了 索引 与 锁 之间的关系,以及死锁成因的简化的情况
- 第一行代码+Android+第2版 笔记第二天
- java基础经典练习题
- eval命令
- Android Studio 2.3 Building项目十分缓慢的解决方法