博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
struts2之防止表单重复提交
阅读量:4079 次
发布时间:2019-05-25

本文共 8732 字,大约阅读时间需要 29 分钟。

struts.xml配置文件

<
struts
>
<
constant name
=
"
struts.ui.theme
"
value
=
"
simple
"
/>
<
package
name
=
"
person
"
namespace
=
"
/test
"
extends
=
"
struts-default
"
>
<
action name
=
"
token
"
class
=
"
com.ljq.action.PersonAction
"
>
<
interceptor
-
ref name
=
"
defaultStack
"
/>
<
interceptor
-
ref name
=
"
token
"
/>
<
result name
=
"
invalid.token
"
>/
WEB
-
INF
/
page
/
error.jsp
<
result
>/
WEB
-
INF
/
page
/
message.jsp
<
action name
=
"
tokenSession
"
class
=
"
com.ljq.action.PersonAction
"
>
<
interceptor
-
ref name
=
"
defaultStack
"
/>
<
interceptor
-
ref name
=
"
tokenSession
"
/>
<
result name
=
"
invalid.token
"
>/
WEB
-
INF
/
page
/
error.jsp
<
result
>/
WEB
-
INF
/
page
/
message.jsp

      

PersonAction类

package    
com.ljq.action;
import
java.util.ArrayList;
import
java.util.List;
public
class
PersonAction {
private
String name; @SuppressWarnings(
"
unchecked
"
)
//
观看控制台
//
如果token生效则不会在控制台输出name的值,而会输出如下警告: 2011-3-14 20:45:32 com.opensymphony.xwork2.util.logging.commons.CommonsLogger
//
warn 警告: Form token EDZ4S96RNDN5VD8B1CQTK6FTHIJUPC66 does not match the session token null.
public
String execute() { List ls
=
new
ArrayList(); ls.add(name);
for
(
int
i
=
0
; i
<
ls.size(); i
++
) { System.out.println(ls.get(i)); }
return
"
success
"
; }
public
String getName() {
return
name; }
public
void
setName(String name) {
this
.name
=
name; }}

      

index.jsp表单页面

<%    
@ page language
=
"
java
"
import
=
"
java.util.*
"
pageEncoding
=
"
UTF-8
"
%>
<%
@ taglib uri
=
"
/struts-tags
"
prefix
=
"
s
"
%>
<
html
>
<
head
>
<
title
>
防止表单重复提交
<
meta http
-
equiv
=
"
pragma
"
content
=
"
no-cache
"
>
<
meta http
-
equiv
=
"
cache-control
"
content
=
"
no-cache
"
>
<
meta http
-
equiv
=
"
expires
"
content
=
"
0
"
>
<
body
>
<
s:form action
=
"
token
"
namespace
=
"
/test
"
method
=
"
post
"
>
姓名:
<
s:textfield name
=
"
name
"
/><
s:token
>
<
input type
=
"
submit
"
value
=
"
发送
"
/>

      

message.jsp返回成功页面

<%    
@ page language
=
"
java
"
import
=
"
java.util.*
"
pageEncoding
=
"
UTF-8
"
%>
<%
@ taglib uri
=
"
/struts-tags
"
prefix
=
"
s
"
%>
<
html
>
<
head
>
<
title
>
My JSP
'
index.jsp
'
starting page
<
meta http
-
equiv
=
"
pragma
"
content
=
"
no-cache
"
>
<
meta http
-
equiv
=
"
cache-control
"
content
=
"
no-cache
"
>
<
meta http
-
equiv
=
"
expires
"
content
=
"
0
"
>
<
body
>
<
s:property value
=
"
name
"
/><
br
/>
<%=
new
Date()
%>

      

error.jsp表单重复提交提示页面

<%    
@ page language
=
"
java
"
import
=
"
java.util.*
"
pageEncoding
=
"
UTF-8
"
%>
<%
@ taglib uri
=
"
/struts-tags
"
prefix
=
"
s
"
%>
<%
String path
=
request.getContextPath();String basePath
=
request.getScheme()
+
"
://
"
+
request.getServerName()
+
"
:
"
+
request.getServerPort()
+
path
+
"
/
"
;
%>
<
html
>
<
head
>
<
base href
=
"
<%=basePath%>
"
>
<
title
>
My JSP
'
error.jsp
'
starting page
<
meta http
-
equiv
=
"
pragma
"
content
=
"
no-cache
"
>
<
meta http
-
equiv
=
"
cache-control
"
content
=
"
no-cache
"
>
<
meta http
-
equiv
=
"
expires
"
content
=
"
0
"
>
<
meta http
-
equiv
=
"
keywords
"
content
=
"
keyword1,keyword2,keyword3
"
>
<
meta http
-
equiv
=
"
description
"
content
=
"
This is my page
"
>
<
body
>
您已经提交了表单,请不要重复提交。

转载地址:http://zcnni.baihongyu.com/

你可能感兴趣的文章
优先级队列-数据结构和算法
查看>>
链接点--数据结构和算法
查看>>
servlet中请求转发(forword)与重定向(sendredirect)的区别
查看>>
Spring4的IoC和DI的区别
查看>>
springcloud 的eureka服务注册demo
查看>>
eureka-client.properties文件配置
查看>>
MODULE_DEVICE_TABLE的理解
查看>>
platform_device与platform_driver
查看>>
platform_driver平台驱动注册和注销过程(下)
查看>>
.net强制退出主窗口的方法——Application.Exit()方法和Environment.Exit(0)方法
查看>>
c# 如何调用win8自带的屏幕键盘(非osk.exe)
查看>>
build/envsetup.sh 简介
查看>>
Android framework中修改或者添加资源无变化或编译不通过问题详解
查看>>
linux怎么切换到root里面?
查看>>
linux串口操作及设置详解
查看>>
安装alien,DEB与RPM互换
查看>>
编译Android4.0源码时常见错误及解决办法
查看>>
Android 源码编译make的错误处理
查看>>
linux环境下C语言中sleep的问题
查看>>
ubuntu 12.04 安装 GMA3650驱动
查看>>