方法一:在客户端利用JS完成
示例如下:
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
var repeatSubmitFlag = false;
function checkSubmit(){
if(repeatSubmitFlag){
window.alert('禁止重复提交');
return false;
}
else{
repeatSubmitFlag = true;
return true;
}
}
</script>
</head>
<body>
<%--
<form action="http://www.baidu.com" method="post" name="form"
onsubmit="return checkSubmit();">
<input name="ck" type="radio" checked />
baidu
<input name="" type="submit" value="submit" />
</form>
--%>
<form action="http://www.baidu.com" method="post" name="form"
onsubmit="window.document.form.submitok.disable=true">
<input name="ck" type="radio" checked />
baidu
<input name="submitok" type="submit" value="submit" />
</form>
</body>
</html>
方法二:在服务器端判断,利用session共享,更有效
<%@ page contentType="text/html; charset=gb2312" %>
<HTML><TITLE>提交页面</TITLE>
<%
//设置标志变量SubmitFlag值ServerTest.jsp
session.putValue("SubmitFlag","ServerTest.jsp");
%>
<BODY BGCOLOR="#FFFFFF">
<form name="form_client" action=ServerSubmit.jsp />
<input type="checkbox" name ="check_1" checked=true />BBS西安交通大学兵马俑站
<input type="submit" name="submitok"/>
</form>
</BODY>
</HTML>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String pageFlag;
pageFlag = (String)session.getAttribute("SubmitFlag");
//out.print(SubmitFlag);
out.print(pageFlag);
if(pageFlag == "Over")
{
out.print("重复提交");
}else{
session.setAttribute("SubmitFlag", "Over");
out.print("正常业务....请等待!");
}
%>
</body>
</html>