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. C++官方文档-静态成员

    #include <iostream> using namespace std; class Dummy { public: static int n; int x; Dummy() : ...

  2. python3.5过滤网址和图片的函数自己亲测可用

    def has_replace(tag): #过滤网址 real=re.sub(r'<a\shref=.+</a>', '',tag.decode(), count=0, flags ...

  3. js1:根据标签的Id获取value值

    例子:<input id="startDate" name="startDate" value="2015-09-14" class= ...

  4. SpringMvc Intercetor

    对于登录的访问控制以及session的超时控制. 当用户在未登录情况下,直接在地址栏输入url进入某些页面时,会越过登录页,如果不做控制会有安全问题. 因此可添加拦截器处理异常: /** * @Des ...

  5. windows平台下 c++获取 系统版本 网卡 内存 CPU 硬盘 显卡信息<转>

    GetsysInfo.h: #ifndef _H_GETSYSINFO #define _H_GETSYSINFO #pragma once #include <afxtempl.h> c ...

  6. ARMV7,ARMV8

    ARMV7是32位,2011年出了ARMV8,是64位架构,IPHONE5S以上都是64位架构,说明是使用ARMV8??

  7. 对 /dev/shm的认识

    一./dev/shm理论 默认的Linux发行版中的内核配置都会开启tmpfs,映射到了/dev/下的shm目录.可以通过df 命令查看结果./dev/shm/是linux下一个非常有用的目录,因为这 ...

  8. Haskell语言学习笔记(62)Divisible

    Divisible class Contravariant f => Divisible f where divide :: (a -> (b, c)) -> f b -> f ...

  9. Haskell语言学习笔记(40)Arrow(1)

    Arrow class Category a => Arrow a where arr :: (b -> c) -> a b c first :: a b c -> a (b, ...

  10. homework 补第三题

    上次只写了两道题 发现少了一道 所以今天补上    4 . 另外补上今天的程序代码 代码 1. 2. 3 4 运行截图 1. 2 3