客户端处理:
面对客户端我们可以使用Javascript脚本来解决,如下
1。重复刷新、重复提交
Ways One:设置一个变量,只允许提交一次。
<script language="javascript">
var checkSubmit*** = false;
function checkSubmit() {
if (checkSubmit*** == true) {
return false;
}
checkSubmit*** = true;
return true;
}
document.ondblclick = function docondblclick() {
window.event.returnValue = false;
}
document.onclick = function doconclick() {
if (checkSubmit***) {
window.event.returnValue = false;
}
}
</script>
<html:form action="myAction.do" method="post" οnsubmit="return checkSubmit();">
Way Two : 将提交按钮或者image置为disable
<html:form action="myAction.do" method="post"
οnsubmit="getElById('submitInput').disabled = true; return true;">
<html:image styleId="submitInput" src="images/ok_b.gif" border="0" />
</html:form>
2.防止用户后退
这里的方法是千姿百态,有的是更改浏览器的历史纪录的,比如使用window.history.forward()方法;有的是“用新页面的URL替换当前的历史纪录,这样浏览历史记录中就只有一个页面,后退按钮永远不会变为可用。”比如使用javascript:location.replace(this.href); event.returnValue=false;
3.struts2防止表单重复提交的方式
<s:token></s:token>
token标签是用于防止多次提交的标签。避免了刷新页面时多次提交,如果需要该标签起作用,则应该在Struts2的配置文件中启用TokenInterceptor拦截器或TokenSessionStoreInterceptor拦截器。
示范代码:
<s:form>
<s:token/>
</s:form>
面对客户端我们可以使用Javascript脚本来解决,如下
1。重复刷新、重复提交
Ways One:设置一个变量,只允许提交一次。
<script language="javascript">
var checkSubmit*** = false;
function checkSubmit() {
if (checkSubmit*** == true) {
return false;
}
checkSubmit*** = true;
return true;
}
document.ondblclick = function docondblclick() {
window.event.returnValue = false;
}
document.onclick = function doconclick() {
if (checkSubmit***) {
window.event.returnValue = false;
}
}
</script>
<html:form action="myAction.do" method="post" οnsubmit="return checkSubmit();">
Way Two : 将提交按钮或者image置为disable
<html:form action="myAction.do" method="post"
οnsubmit="getElById('submitInput').disabled = true; return true;">
<html:image styleId="submitInput" src="images/ok_b.gif" border="0" />
</html:form>
2.防止用户后退
这里的方法是千姿百态,有的是更改浏览器的历史纪录的,比如使用window.history.forward()方法;有的是“用新页面的URL替换当前的历史纪录,这样浏览历史记录中就只有一个页面,后退按钮永远不会变为可用。”比如使用javascript:location.replace(this.href); event.returnValue=false;
3.struts2防止表单重复提交的方式
<s:token></s:token>
token标签是用于防止多次提交的标签。避免了刷新页面时多次提交,如果需要该标签起作用,则应该在Struts2的配置文件中启用TokenInterceptor拦截器或TokenSessionStoreInterceptor拦截器。
示范代码:
<s:form>
<s:token/>
</s:form>