困饶好久的问题,大家都帮忙,解决一定再加分
这段代码 向数据库插一条记录,但莫明奇妙的会一下子插入2条相同的数据
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* " errorPage= " " %>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 信息录入 </title>
//数据库连接JDBC
<jsp:useBean id= "connection " scope= "request " class= "com.JDBConnection "/>
//一个获取系统时间的bean
<jsp:useBean id= "showTime " scope= "request " class= "com.ShowTime "/>
</head>
<link href= "css/style.css " type= "text/css " rel= "stylesheet ">
<body> <br> <br> <br>
<table width= "289 " border= "0 " align= "center " cellpadding= "0 " cellspacing= "0 " background= "image/registerDealwith.jpg ">
<tr>
<td height= "34 "> <font color= "#FFFFFF "> ≡ 注册结果 ≡ </font> </td>
</tr>
<tr align= "center ">
<td height= "206 ">
<%
//为用户注册功能,下面数据是从注册页传来的
request.setCharacterEncoding( "gb2312 ");
String account=request.getParameter( "account ");
String realname=request.getParameter( "realname ");
String password=request.getParameter( "password1 ");
String sex=request.getParameter( "sex ");
String bron=request.getParameter( "bron ");
String tel=request.getParameter( "tel ");
String email=request.getParameter( "email ");
String QQ=request.getParameter( "QQ ");
String office=request.getParameter( "office ");
String CIQ=request.getParameter( "CIQ ");
//insert语句
String sql= "insert into t_user (account,realname,password,sex,bron,tel,email,QQ,office,CIQ,userRight) values( ' "+account+ " ', ' "+realname+ " ', ' "+password+ " ', ' "+sex+ " ', ' "+bron+ " ', ' "+tel+ " ', ' "+email+ " ', ' "+QQ+ " ', ' "+office+ " ', ' "+CIQ+ " ', '0 ') ";
if(connection.executeUpdate(sql)){%>
<p> <b> <font color= "#FF0000 "> 恭喜你注册成功! </font> </b> </p>
<meta http-equiv= "refresh " content= "5;URL=index.jsp "> //如不用自动跳转就没问题
<%}else{%>
<p> <b> <font color= "#FF0000 "> 该用户名已存在!请重新注册! </font> </b> </p>
<meta http-equiv= "refresh " content= "5;URL=index.jsp "> //如不用自动跳转就没问题
<%}%>
<%connection.closeConnection();%>
<p> <a href= "index.jsp "> (如果您的浏览器无法自动跳转,请点击这里。) </a> </p> </td>
</tr>
</tr>
</table>
</body>
</html>
实在不明白 ,请大家多帮忙啊,找到问题的一定加分.
[解决办法]
可能是jsp代码的问题,应该是页面提交了两次,不是数据库的问题,LZ去java版问问好了
[解决办法]
跟踪调试.看看是否两次提交?