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. ...
随机推荐
- C++官方文档-常量成员函数
#include <iostream> using namespace std; class MyClass { public: int x; static int n; const in ...
- oracle10偶然性卡住登陆
连接数据库异常:登陆数据库后以"conn /as sysdba"方式登陆正常,数据库轻载,无压力:于是检查数据库的监听器,输入"lsntctl services" ...
- rsyslog编译依赖问题解决
bit-32-centos6.4测试loganalyzer+mysql+rsyslog web界面中央日志分析系统.1,报json-c错误wget http://cloud.github.com/ ...
- leetcode171
public class Solution { private int ConvertToC(char c) { ; switch (c) { case 'A': case 'a': rnt = ; ...
- Eclipse安装Svn无法连接问题
在Eclipse市场上安装完SVN插件后连接SVN时出现以下错误: SVN: '0x00400006: Validate Repository Location' operation finished ...
- com.google.gson的SerializedName解决实体类与关键字的重名
使用google的gson包,解决实体类中字段与java关键字的重名: // 比如 当实体类中有switch关键字时,解决冲突如下 @SerializedName("switch" ...
- Ansible playbooks
Playbook是Ansible的配置,部署和编排语言. 他们可以描述您希望远程系统执行的策略,或一般IT流程中的一组步骤. 如果Ansible modules是您workshop的工具,则playb ...
- js 获取input选择的图片的信息
1JS $("#btn").click(function () { var imageEle = document.getElementById("images" ...
- electron sendInputEvent keyboard
https://github.com/electron/electron/issues/5005 webview.getWebContents().sendInputEvent({ type: 'ch ...
- maven package install deploy
1.maven package:打包到本项目,一般是在项目target目录下. 如果a项目依赖于b项目,打包b项目时,只会打包到b项目下target下,编译a项目时就会报错,因为找不到所依赖的b项目, ...