1.struts 防止表单重复提交 2. 拦截器
1. 使用struts 防止表单提交 时, form 表单必须使用struts标签库编写,如<s:form/> 等,而不是html标签
2. 拦截器是struts2的核心。 interceptor接口
package com.interceptor; import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor; /**
* 1. 实现interceptor接口
* 2. struts.xml 配置 interceptors 拦截器
* 3. 在struts.xml action中 配置 interceptor-ref 使用
* 4. set 方法会在init 方法前执行
* @author Administrator
*
*/ public class Myinterceptor implements Interceptor{
private String test;
//getter 和setter 方法
@Override public void destroy() { }
@Override public void init() { } // test 的初始化会在 init 前
@Override public String intercept(ActionInvocation arg0) throws Exception {
System.out.println("before");
return arg0.invoke();
System.out.println("after");
}
}
<interceptors>
<interceptor name="theInteceptor" class="com.interceptor.Myinterceptor">
<param name="test">12</param>
</interceptor>
<interceptor name="theInteceptor2" class="com.interceptor.StrutsInterceptor">
<param name="test">12</param>
</interceptor>
</interceptors>
<global-exception-mappings>
<exception-mapping result="globalerror" exception="Exception"></exception-mapping>
</global-exception-mappings>
<global-results>
<result name="globalerror">/index.jsp</result>
</global-results>
<action name="login" class="com.login.Login">
<result name="success">/index.jsp</result>
<!-- action 错误 调整 -->
<exception-mapping result="error" exception="com.exception.Myexception"></exception-mapping><!-- 可以自定义错误类型 -->
<result name="error">/index.jsp</result>
<interceptor-ref name="theInteceptor"></interceptor-ref> <!--如果指定了自定义拦截器,defaultstack 就不起作用了。
需要将defaultstack拦截器添加到自定义拦截器后,否则struts2的一些功能可能不起作用-->
<interceptor-ref name="theInteceptor2"></>
</action>
<!--调用该action 拦截器的执行 输出 顺序是 before ,inteceptor before, inteceptor after,after ... 拦截器默认拦截的是action的execute 方法
那么如何拦截自定义方法呢??需要用到方法拦截器MethodFilterInterceptor: includeMethods,excludeMethods 指定方法名,如果某个方法在两个里面都
有的话,includeMethods 级别更高,所以会拦截。 实现MethodFilterInterceptor ,重写doInterceptor 方法
-->
package com.interceptor; import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor; /**
* struts 拦截器 ,,通常是实现 AbstractInterceptor, 而不是直接实现Interceptor 接口
* @author Administrator
*
*/ public class StrutInterceptor extends AbstractInterceptor{ @Override
public String intercept(ActionInvocation arg0) throws Exception {
System.out.println("interceptor before");
String result=arg0.invoke();//invoke()指 拦截器完成后继续执
System.out.println("interceptor after");
return result;
} }
1.struts 防止表单重复提交 2. 拦截器的更多相关文章
- 大型运输行业实战_day05_1_登录+注销+表单重复提交+登录拦截器
1.登录 登录实现如下步骤: 1.在首页中添加登录按钮 html代码如下: <%@ page contentType="text/html;charset=UTF-8" la ...
- Struts防止表单重复提交
1.什么是表单重复提交 > 在不刷新表单页面的前提下: >> 多次点击提交按钮 >> 已经提交成功, 按 "回退" 之后 ...
- JavaWeb -- Session实例 -- 自动登录 和 防止表单重复提交(令牌产生器) MD5码
1. 自动登录 http://blog.csdn.net/xj626852095/article/details/16825659 2. 防止表单重复提交 表单Servlet //负责产生表单 pub ...
- 由防止表单重复提交引发的一系列问题--servletRequest的复制、body值的获取
@Time:2019年1月4日 16:19:19 @Author:QGuo 背景:最开始打算写个防止表单重复提交的拦截器:网上见到一种不错的方式,比较合适前后端分离,校验在后台实现: 我在此基础上 ...
- struts2之防止表单重复提交
struts.xml配置文件 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts ...
- struts2的防止表单重复提交
防止表单重复提交其实就是struts2的一个拦截器的使用: struts.xml配置文件: <?xml version="1.0" encoding="UTF-8& ...
- 使用Struts 2防止表单重复提交
用户重复提交表单在某些场合将会造成非常严重的后果.例如,在使用信用卡进行在线支付的时候,如果服务器的响应速度太慢,用户有可能会多次点击提交按钮,而这可能导致那张信用卡上的金额被消费了多次.因此,重复提 ...
- struts2视频学习笔记 29-30(Struts 2常用标签,防止表单重复提交)
课时28 Struts 2常用标签解说 property标签 property标签用于输出指定值: <s:set name="name" value="'kk'&q ...
- Struts(二十七):使用token或tokenSession防止表单重复提交
什么是表单重复提交 表单重复提交包括以下几种情况: 前提:不刷新表单页面 1.多次点击“提交”按钮后,重复提交了多次: 2.已经提交成功之后,按“回退”按钮之后,在点击“提交”按钮后,提交成功: 3. ...
随机推荐
- python 编码文件json.loads json.dumps
import yaml d = {'name': '张三', 'age': '1'} print d jd = json.dumps(d, ensure_ascii=False, encoding=' ...
- 代码:css小图标
向下小箭头 .icon-tip{ border-color: transparent transparent #bb0808 transparent; border-style:solid; bord ...
- requireJS-初识
浅谈requireJS 2016-04-26 21:44 by 猴子猿, 726 阅读, 0 评论, 收藏, 编辑 项目中大都使用模块化开发,requireJS作为AMD模块开发的典范,所以有必要学习 ...
- nginx 无法访问root权限的文件内容
问题: 按照的nginx,nginx配置的user 是 nginx,nginx 是root用户启动的. 文件夹A放的那啥是root用户上传的文件. 可 nginx 无法访问 到 文件. 方法: ...
- 吴裕雄 python 数据处理(2)
import pandas as pd data = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\hz ...
- SQL 数据库主键 ,外键
主键 数据库主键是指表中一个列或列的组合,其值能唯一地标识表中的每一行.这样的一列或多列称为表的主键,通过它可强制表的实体完整性.当创建或更改表时可通过定义 PRIMARY KEY约束来创建主键.一个 ...
- vmstat工具
vmstat vmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写, 是实时系统监控工具.该命令通过使用knlist子程序和/dev/kmen伪设备驱动器访问这些数 ...
- List<?>和List<T>的区别
是java泛型的两种用法:List<T>是泛型方法,List<?>是限制通配符 List<T>一般有两种用途:1.定义一个通用的泛型方法.伪代码: public i ...
- 基于mysql全文索引的深入理解
最近要使用mysql的全文索引,一直没能成功,一个是只有MyISAM引擎支持,创建表时需要指定,而是需要对my.ini进行配置. 前言:本文简单讲述全文索引的应用实例,MYSQL演示版本5.5.24. ...
- Resume (Curriculum Vitae)
The resume (Curriculum Vitae) is a selling tool outlining your skills and experience so an employer ...