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. 拦截器的更多相关文章

  1. 大型运输行业实战_day05_1_登录+注销+表单重复提交+登录拦截器

    1.登录 登录实现如下步骤: 1.在首页中添加登录按钮 html代码如下: <%@ page contentType="text/html;charset=UTF-8" la ...

  2. Struts防止表单重复提交

    1.什么是表单重复提交 > 在不刷新表单页面的前提下:         >> 多次点击提交按钮        >> 已经提交成功, 按 "回退" 之后 ...

  3. JavaWeb -- Session实例 -- 自动登录 和 防止表单重复提交(令牌产生器) MD5码

    1. 自动登录 http://blog.csdn.net/xj626852095/article/details/16825659 2. 防止表单重复提交 表单Servlet //负责产生表单 pub ...

  4. 由防止表单重复提交引发的一系列问题--servletRequest的复制、body值的获取

    @Time:2019年1月4日 16:19:19 @Author:QGuo   背景:最开始打算写个防止表单重复提交的拦截器:网上见到一种不错的方式,比较合适前后端分离,校验在后台实现: 我在此基础上 ...

  5. struts2之防止表单重复提交

    struts.xml配置文件 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts ...

  6. struts2的防止表单重复提交

    防止表单重复提交其实就是struts2的一个拦截器的使用: struts.xml配置文件: <?xml version="1.0" encoding="UTF-8& ...

  7. 使用Struts 2防止表单重复提交

    用户重复提交表单在某些场合将会造成非常严重的后果.例如,在使用信用卡进行在线支付的时候,如果服务器的响应速度太慢,用户有可能会多次点击提交按钮,而这可能导致那张信用卡上的金额被消费了多次.因此,重复提 ...

  8. struts2视频学习笔记 29-30(Struts 2常用标签,防止表单重复提交)

    课时28 Struts 2常用标签解说 property标签 property标签用于输出指定值: <s:set name="name" value="'kk'&q ...

  9. Struts(二十七):使用token或tokenSession防止表单重复提交

    什么是表单重复提交 表单重复提交包括以下几种情况: 前提:不刷新表单页面 1.多次点击“提交”按钮后,重复提交了多次: 2.已经提交成功之后,按“回退”按钮之后,在点击“提交”按钮后,提交成功: 3. ...

随机推荐

  1. 2.1_Scikit-learn数据集

    scikit-learn数据集 我们将介绍sklearn中的数据集类,模块包括用于加载数据集的实用程序,包括加载和获取流行参考数据集的方法.它还具有一些人工数据生成器. sklearn.dataset ...

  2. Openstack虚机实例状态错误手工恢复vm_state:error

    Openstack虚机实例状态错误手工恢复vm_state:error 1.找到状态为出错状态的VM.在数据库里面表现Status为ERROR而非ACTIVE. 2.找到出错状态VM的UUID. 3. ...

  3. 温故而知新-mysql高级管理

    温故而知新-mysql高级管理 1 mysql的一些授权信息都保存在授权表中 授权表是6个 db,user,host,tables_priv,columns_priv,procs_priv 这6个表 ...

  4. centos7.3 快速安装 mariadb(mysql)

    从最新版本的linux系统开始,默认的是 Mariadb而不是mysql! 使用系统自带的repos安装很简单: yum install mariadb mariadb-server systemct ...

  5. OpenACC 优化矩阵乘法

    ▶ 按书上的步骤使用不同的导语优化矩阵乘法 ● 所有的代码 #include <iostream> #include <cstdlib> #include <chrono ...

  6. EF时间模糊查询

    public List<Vote> SelectVoteByTime(string time) { return db.Vote.ToList().Where(x => x.V_Be ...

  7. Unified shader model

    https://en.wikipedia.org/wiki/Unified_shader_model In the field of 3D computer graphics, the Unified ...

  8. state介绍

    state是salt最核心的功能,通过预先定制好的sls(salt state file)文件对被控主机进行状态管理,支持包括程序包(pkg).文件(file).网络配置(network).系统服务( ...

  9. DataFrame 取值

    通过 DataFrame[ ]方式,取得得都是行, [ ] 中,添加过滤条件 data = pd.DataFrame( np.arange(16).reshape(4,4), index=['OP', ...

  10. 框架中spring有专门的类用于处理乱码

    在三大框架spring中有专门的一个过滤器类用于处理乱码问题--->CharacterEncodingFilter 我们只需在web.xml中添加如下几行代码就可解决乱码问题 <filte ...