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. ...
随机推荐
- attack source code
不废话,直接上代码, 先看截图use pictures;
- (11/24) css进阶:Less文件的打包和分离
写在前面:在前面我们对css打包和分离进行了描述.此节我们开始学习如何对less文件进行打包和分离. Less 是一门 CSS 预处理语言,它扩展了 CSS 语言,增加了变量.Mixin.函数等特性, ...
- (6/24) 插件配置:轻松配置JS文件压缩
实际开发中,在项目上线之前,我们编写的js代码是需要进行压缩的,我们可以采取压缩软件或者在线进行压缩,这不是我们的重点,在webpack中实现JS代码的压缩才是本节的核心. 通过webpack中可实现 ...
- quartz 定时任务的增删改
参考: https://blog.csdn.net/llmys/article/details/81069863
- leetcode754
class Solution { public: int reachNumber(int target) { // 理解这题的意思 这题就好做了 // 分析 首先考虑一种比较极端的情况 即一直向正方向 ...
- Spring MVC 数据绑定流程
DataBinder 数据绑定 入参,校验,格式化, ConversionService: 进行数据类型转换和数据格式化 Validators 进行数据合法性的校验, 把结果放入BindingResu ...
- CStatic控件SS_NOTIFY属性
SS_NOTIFY Sends the parent window STN_CLICKED, STN_DBLCLK, STN_DISABLE, and STN_ENABLE notification ...
- 通过sizeof获得数组长度的方法
int a[20]; int len = sizeof(a)/sizeof(*a); //值为20,即数组长度为20 注:sizeof是一个操作符,sizeof的值在编译时确定
- 通过关闭 UseDNS和GSSAPIAuthentication选项加速 SSH登录
通常情况下我们在连接 OpenSSH服务器的时候假如 UseDNS选项是打开的话,服务器会先根据客户端的 IP地址进行 DNS PTR反向查询出客户端的主机名,然后根据查询出的客户端主机名进行DNS正 ...
- 迷你MVVM框架 avalonjs 1.3.7发布
又到每个月的15号了,现在avalon已经固定在每个月的15号发布新版本.这次发布又带来许多新特性,让大家写码更加轻松,借助于"操作数据即操作DOM"的核心理念与双向绑定机制,现在 ...