请高手帮我看看,我这个页面为何会出现重复提交的情况? ( 积分: 50 )

  • 主题发起人 tswhoney
  • 开始时间
T

tswhoney

Unregistered / Unconfirmed
GUEST, unregistred user!
我的服务是Tomcat5.0,页面代码如下,为何每次提交都会连续提交2条记录到数据库,而且有时又是正常的.
<%@include file="/include/tools/SessionCheck.jsp"%>
<%@ page import="java.sql.*,com.ConnectDB,java.util.*"
contentType="text/html;
charset=GBK"
errorPage="/error.jsp"
%>
<%@ page import="com.sowant.eip.com.properties.*"%>
<jsp:useBean id="conn"
scope="page"
class="com.ConnectDB"
/>
<html>
<head>
<title>网址设定</title>
<meta http-equiv="Content-Type"
content="text/html;
charset=GBK">
</head>
<script language="javascript">
function addwz()
{
if (form1.t1.value=="")
{
alert('网址简称要填写');
form1.t1.focus();
return false;
}
if (form1.t2.value=="")
{
alert('网址全称要填写');
form1.t2.focus();
return false;
}
if (form1.t3.value == 0)
{
alert('网址路径要填写');
form1.t3.focus();
return false;
}
else
{

form1.submit();
}
}
</script>
<%
if (request.getMethod().equals("POST"))
{
String sqlstr="insert into CYGL_wz_manage(wzname,wzhttp,wzname2) values("+convert(request.getParameter("t1"))+","+convert(request.getParameter("t3"))+
","+convert(request.getParameter("t2"))+")";
conn.execute(sqlstr);
}
%>

<body>
<p> 
</p>
<form name="form1"
method="post"
onsubmit="return addwz()">
<table width="365"
border="0"
align="center">
<tr class="trLine1_1">
<td width="47"
height="24">简称:</td>
<td width="322"><input name="t1"
type="text"
id="t1"></td>
</tr>
<tr>
<td height="25">全称:</td>
<td><input name="t2"
type="text"
id="t2"
size="35"
maxlength="50"></td>
</tr>
<tr>
<td height="25">网址:</td>
<td><input name="t3"
type="text"
id="t3"
value="http://"
size="40"></td>
</tr>
<tr>
<td> </td>
<td> 
<input type="image"
src="/new_image/button3.gif"
style="cursor:hand"
width="55"
height="20"
>
<img src="/new_image/button4.gif"
width="55"
height="20"
style="cursor:hand"
onclick="window.close()">
</td>
</tr>
</table>
</form>
</body>
</html>
 
我的服务是Tomcat5.0,页面代码如下,为何每次提交都会连续提交2条记录到数据库,而且有时又是正常的.
<%@include file="/include/tools/SessionCheck.jsp"%>
<%@ page import="java.sql.*,com.ConnectDB,java.util.*"
contentType="text/html;
charset=GBK"
errorPage="/error.jsp"
%>
<%@ page import="com.sowant.eip.com.properties.*"%>
<jsp:useBean id="conn"
scope="page"
class="com.ConnectDB"
/>
<html>
<head>
<title>网址设定</title>
<meta http-equiv="Content-Type"
content="text/html;
charset=GBK">
</head>
<script language="javascript">
function addwz()
{
if (form1.t1.value=="")
{
alert('网址简称要填写');
form1.t1.focus();
return false;
}
if (form1.t2.value=="")
{
alert('网址全称要填写');
form1.t2.focus();
return false;
}
if (form1.t3.value == 0)
{
alert('网址路径要填写');
form1.t3.focus();
return false;
}
else
{

form1.submit();
}
}
</script>
<%
if (request.getMethod().equals("POST"))
{
String sqlstr="insert into CYGL_wz_manage(wzname,wzhttp,wzname2) values("+convert(request.getParameter("t1"))+","+convert(request.getParameter("t3"))+
","+convert(request.getParameter("t2"))+")";
conn.execute(sqlstr);
}
%>

<body>
<p> 
</p>
<form name="form1"
method="post"
onsubmit="return addwz()">
<table width="365"
border="0"
align="center">
<tr class="trLine1_1">
<td width="47"
height="24">简称:</td>
<td width="322"><input name="t1"
type="text"
id="t1"></td>
</tr>
<tr>
<td height="25">全称:</td>
<td><input name="t2"
type="text"
id="t2"
size="35"
maxlength="50"></td>
</tr>
<tr>
<td height="25">网址:</td>
<td><input name="t3"
type="text"
id="t3"
value="http://"
size="40"></td>
</tr>
<tr>
<td> </td>
<td> 
<input type="image"
src="/new_image/button3.gif"
style="cursor:hand"
width="55"
height="20"
>
<img src="/new_image/button4.gif"
width="55"
height="20"
style="cursor:hand"
onclick="window.close()">
</td>
</tr>
</table>
</form>
</body>
</html>
 
if (form1.t3.value == 0)
{
alert('网址路径要填写');
form1.t3.focus();
return false;
}
else
{

return true;
//form1.submit();这里不对
}
}
 
楼上说的对,把else
去掉。
 
else
{

form1.submit();
}

改为 return true;
如果用else
,相当于提交了两次
 
顶部