JSP+数据库的问题,我相信一定有高手,急!
问题是为什么表单的内容提交到register.jsp页面时不出register.html页的内容呢,听说缺一个JAVABEAN不知如何写。
现在把这全部代码写出来。望高手帮助我!
register.html页代码
<!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=gb2312">
<title>用户注册界面</title>
<script language="javascript">
function isValid(form){
if(form.name.value==""){
alert(" 用户名不能为空!");
return false;
}
else if((form.password.value.length<3)||(form.password.value.length>8)){
alert("密码必须是3-8位字母或数字!");
return false;
}
else if((form.e_mail.value=="")||(form.e_mail.value.indexOf('@',0)==-1)||
(form.e_mail.value.indexOf('.',0)==-1)||(form.e_mail.value.length<6)){
alert("请您输入合法的E-mail地址!");
return false;
}
else{
return false;
}
}
</script>
</head>
<body>
<p align="center">JSP表单程序设计</center>
<br>
<form method="post" action="register.jsp" onSubmit="isValid(this);">
<table border="1" cellspacing="1" height="191" bordercolorlight="#993300" bordercolordark="#00CC66" width="500">
<tr>
<td height="14" valign="top" colspan="2">
<p>请输入您的个人信息(标注*的内容必须填写)</p>
</td>
</tr>
<tr>
<td height="14" width="76" align="center">用户名:</td>
<td width="411" height="14" align="left"><font color="#524581">
<input type="text" name="name" size="20">
<font color="#FF0080">*</font></font></td>
</tr>
<tr>
<td height="14" width="76" align="center">密码:</td>
<td width="411" height="14" align="left"><font color="#524581">
<input name="pwd" type="password" id="password" size="20" maxlength="20">
<font color="#FF0080">*</font></font></td>
</tr>
<tr>
<td height="14" width="76" align="center">确认密码:</td>
<td width="411" height="14" align="left"><font color="#524581">
<input type="password" name="Ok_password" size="20" maxlength="20">
<font color="#FF0080">*</font></font></td>
</tr>
<tr>
<td height="14" width="76" align="center">性别:</td>
<td width="411" height="14" align="left"><font color="#524581">
男<input type="radio" name="sex" value="male" checked>
女<input type="radio" name="sex" value="female">
<font color="#FF0080">*</font></font></td>
</tr>
<tr>
<td height="14" width="76" align="center">E-mail:</td>
<td width="411" height="14" align="left"><font color="#524581">
<input type="text" name="e_mail" size="40" maxlength="40">
<font color="#FF0088">*</font></font></td>
</tr>
<tr>
<td height="14" width="76" align="center">主页:</td>
<td width="411" height="6" align="left"><font color="#524581">
<input type="text" name="url" size="40" maxlength="40" value="http://">
<font color="#FF0088">*</font></font></td>
</tr>
</table>
<br>
<input type="submit" size="4" value="立即注册">
</form>
</center>
</body>
</html>
register.jsp页代码
<%@ page contentType="text/html; charset=gb2312"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>注册用户确认</title>
</head>
<body>
<center>
<%@ page language="java" import="java.sql.*"%>
<jsp:useBean id="RegisterBean" scope="page" class="DataBase.MyDbBean"/>
<%
//获得传递来的变量
String name=request.getParameter("name");
String password=request.getParameter("password");
String re_password=request.getParameter("Ok_password");
String sex=request.getParameter("sex");
String e_mail=request.getParameter("e_mail");
String url=request.getParameter("url");
String sql="select * from reg where names='"+name+"'";
RegisterBean.OpenConn("register","","");
ResultSet rs=RegisterBean.executeQuery("sql");
//以用户输入名为条件检索记录,如存在表示用户名已被占用
if(rs.next()){
rs.close();
out.println("您的用户名已被占用,请换一个重新再试");
//自动跳到注册界面
response.sendRedirect("register.html");
}
else{
//否则,向数据库中插入记录
String strSQL="insert into reg values('"+name+"','"+pwd+"','"+re_password+"','"+sex+"','"+e_mail+"','"+url+"')";
RegisterBean.executeUpdate(strSQL);
%>
<!--显示用户信息-->
<table border="1" cellspacing="1" height="191" width="527" bordercolordark="#FF0000" bordercolorlight="#CCCCCC"#">
<tr>
<td height="1" width="517" valign="top" colspan="2">
<p>用户信息如下: </p>
</td>
</tr>
<tr>
<td height="14" width="123" align="left">用户名:</td>
<td width="388" height="10" align="left"><font color="#524581">
<%=name%></font></td>
</tr>
<tr>
<td height="14" width="123" align="left">密码:</td>
<td width="388" height="10" align="left"><font color="#524581">
<%=password%></font></td>
</tr>
<tr>
<td height="14" width="123" align="left">确认密码:</td>
<td width="388" height="10" align="left"><font color="#524581">
<%=re_password%></font></td>
</tr>
<tr>
<td height="14" width="123" align="left">性别:</td>
<td width="388" height="10" align="left"><font color="#524581">
<%=sex%></font></td>
</tr>
<tr>
<td height="14" width="123" align="left">E-mail:</td>
<td width="388" height="10" align="left"><font color="#524581">
<%=e_mail%></font></td>
</tr>
<tr>
<td height="14" width="123" align="left">主页:</td>
<td width="388" height="10" align="left"><font color="#524581">
<%=url%></font></td>
</tr>
</table>
<%
out.println("您注册成功了!");
rs.close();
}
%>
</body>
</html>