struts2使用Interceptor接口来实现拦截器
来源:互联网 发布:什么得什么知成语 编辑:程序博客网 时间:2024/05/16 12:52
1.interceptor使用
写个类实现interceptor接口
public class PermissionInterceptor implements interceptor{
重写 intercept方法方法返回值String代表result name 的值
public String intercept(ActionInvocation invocation){
if(session里存在用户)
{
return invocation.invoke();
}
return 返回消息页面;
}
}
2.在Struts.xml中配置拦截器
<package name="xx" extends="struts-default">
<interceptors>
<interceptor name="permission" class="PermissionInterceptor"/>
<interceptor-stack name="permissionStack">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="permission"/>
<interceptor-stack>
</interceptors>
<action name="xxx_*" class="xxx" method="{1}">
<result name="xxx">xxxxx.jsp</result>
<interceptor-ref neme="permissionStack"/>
</action>
</package>
因为struts2中如文件上传,数据验证,封装请求参数到Action等功能都是由系统默认的defaultStack中的拦截器
实现的,所以我们定义的拦截器需要引用系统默认的defaultStack。这样才可以使用struts2框架提供的众多功能。
如果希望包下的所有action都使用自定义拦截器,
可以通过<default-interceptor-ref name="permissionStack"/>把拦截器定义为默认拦截器。
注意:每个包只能指定一个默认拦截器,另外,一旦我们为该包的某个action显示指定了某个拦截器,
则默认拦截器不会起作用。
0 0
- struts2使用Interceptor接口来实现拦截器
- struts2的拦截器(3):通过实现Interceptor接口定义自己的拦截器
- Struts2中Interceptor拦截器的使用
- Struts2 Interceptor 拦截器的使用流程
- Struts2拦截器(Interceptor)
- Struts2拦截器(Interceptor)
- struts2 拦截器 interceptor
- struts2 拦截器 interceptor
- Struts2拦截器(Interceptor)
- Struts2拦截器(Interceptor)
- Struts2拦截器(Interceptor)
- Struts2拦截器(Interceptor)
- Struts2拦截器(Interceptor)
- Struts2拦截器(Interceptor)
- Struts2拦截器(Interceptor)
- Struts2拦截器(Interceptor)
- Struts2拦截器(Interceptor
- struts2 拦截器 interceptor
- ios HTTP协议的理解
- UVa Puzzle——C语言版本
- temp
- 1009. 说反话
- html5的replaceState实现详情页到列表页的无刷新且回到上次位置
- struts2使用Interceptor接口来实现拦截器
- 5.0图片的转场动画
- 1010. 一元多项式求导
- 第四周项目5-用递归方法求解(3)
- 关于用css3 还是img
- apache phoenix UDF example
- 输出gradle执行task名称、输入输出文件和耗时
- ubuntu下Qt for Android的安装及环境配置
- zoj 3872(dp)