Struts2使用15 -- 拦截器5 -- 实例
来源:互联网 发布:苹果mac密码忘了怎么办 编辑:程序博客网 时间:2024/05/20 16:10
实例一:防止表单重复提交
防止重复提交:有两种方法:一是使用token拦截器,二是使用tokenSession
第一种方法步骤:
1、 先在页面中放一个令牌。调用Struts标签,服务器自动分派。<s:token></s:token>
2、 在struts.xml文件定义token拦截器。
<interceptor-ref name="token"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
3、 在struts.xml文件配置有重复提交的错误页面,即:
<result name="invalid.token">/repeatSubmitError.jsp</result>
第二种方法基本与第一种方法基本相同,只不用配置重复提交的错误页面,如果发生重复提交,返回success。
实例二:PreResultInteceptor
这个功能是在Action返回到result时执行。
拦截器 --> Action --> Result --> 拦截器
实现步骤:
1、 定义一个类实现PreResultListener接口,实现beforeResult方法
public class TestPreResultInteceptor implements PreResultListener {
public void beforeResult(ActionInvocation arg0, String arg1) {
System.out.println("在结果集返回之前执行了beforeResult方法");
}
}
2、 自定义一个拦截器与上面定义类进行绑定。
public class TestInterceptor extends AbstractInterceptor {
@Override
public String intercept(ActionInvocation invocation) throws Exception {
invocation.addPreResultListener(new TestPreResultInteceptor());
System.out.println("在action执行execute方法之前执行进行拦截");
String result = invocation.invoke();
System.out.println("在action执行execute方法之后执行进行拦截");
return result;
}
}
- Struts2使用15 -- 拦截器5 -- 实例
- struts2对拦截器使用带实例
- Struts2拦截器实例-权限拦截器
- struts2 拦截器实现实例
- Struts2拦截器的实例
- struts2拦截器配置实例
- Struts2拦截器配置实例
- struts2-timer拦截器实例
- struts2中拦截器使用的代码实例
- struts2拦截器使用
- struts2使用拦截器
- struts2拦截器使用
- 5、struts2 拦截器
- Struts2拦截器的使用
- Struts2拦截器的使用
- struts2拦截器的使用
- Struts2拦截器的使用
- Struts2.X 拦截器使用
- Struts2使用13 -- 拦截器3 -- 内置拦截器
- php5.3改动
- 请高手指点
- Struts2使用14 -- 拦截器4 -- 自定义拦截器
- DHTML (JavaScript Dom 编程艺术)
- Struts2使用15 -- 拦截器5 -- 实例
- ssh例子
- 报错:"该连接已关闭"
- ActionScript登場
- Struts2使用16 -- 值栈与 OGNL 1 -- 概述
- VS2005 出现warning C4996: strcpy was declared deprecated
- 是
- 固定table的宽度
- JavaScript版本 质数(也叫素数)算法