注册页面输入数据库失败?
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="utf-8"%><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
function checkname(){
var div = document.getElementById("div1");
div.innerHTML = "";
var name1 = document.form1.uname.value;
if (name1 == "") {
div.innerHTML = "姓名不能为空!";
document.form1.uname.focus();
return false;
}
if (name1.length < 4 || name1.length > 16) {
div.innerHTML = "姓名输入的长度4-16个字符!";
document.form1.uname.select()();
return false;
}
var charname1 = name1.toLowerCase();
for (var i = 0; i < name1.length; i++) {
var charname = charname1.charAt(i);
if (!(charname >= 0 && charname <= 9) && (!(charname >= 'a' && charname <= 'z')) && (charname != '_')) {
div.innerHTML = "姓名包含非法字母,只能包含字母,数字,和下划线";
document.form1.uname.select()();
return false;
}
}
return true;
}
function checkpassword(){
var div = document.getElementById("div2");
div.innerHTML = "";
var password = document.form1.upassword.value;
if (password == "") {
div.innerHTML = "密码不位空!";
document.form1.upassword.focus();
return false;
}
if (password.length < 4 || password.length > 12) {
div.innerHTML = "密码长度4-12位";
document.form1.upassword.select()();
return false;
}
return true;
}
function checkrepassword(){
var div = document.getElementById("div3");
div.innerHTML = "";
var password = document.form1.upassword.value;
var repass = document.form1.upassword1.value;
if (repass == "") {
div.innerHTML = "密码不位空!";
document.form1.upassword1.focus();
return false;
}
if (password != repass) {
div.innerHTML = "输入密码和确认密码长度不一致";
document.form1.upassword1.select();
return false;
}
return true;
}
function checkEmail(){
var div = document.getElementById("div4");
div.innerHTML = "";
var email = document.form1.uemail.value;
var sw = email.indexOf("@", 0);
var sw1 = email.indexOf(".", 0);
var tt = sw1 - sw;
if (email.length == 0) {
div.innerHTML = "电子邮件不能位空";
document.form1.uemail.focus();
return false;
}
if (email.indexOf("@", 0) == -1) {
div.innerHTML = "电子邮件格式不正确,必须包含@符号!";
document.form1.uemail.select();
return false;
}
if (email.indexOf(".", 0) == -1) {
div.innerHTML = "电子邮件格式不正确,必须包含.符号!";
document.form1.uemail.select();
return false;
}
if (tt == 1) {
div.innerHTML = "邮件格式不对。@和.不可以挨着!";
document.form1.uemail.select();
return false;
}
if (sw > sw1) {
div.innerHTML = "电子邮件格式不正确,@符号必须在.之前";
document.form1.uemail.select();
return false;
}
else {
return true;
}
return ture;
}
function check(){
if (checkname() && checkpassword() && checkrepassword() && checkEmail()) {
return true;
}
else {
return false;
}
}
</script>
</head>
<body>
<div align="center">
<form name="form1" method="post" action="index_check.jsp" onsubmit="return check()">
<table>
<tr>
<td>
用户名:
</td>
<td>
<input id="uname" type="text" name="uname" onblur="check()">
<div id="div1" style="display:inline">
</div>
</td>
</tr>
<tr>
<td>
密码:
</td>
<td>
<input id="upassword" type="password" name="upassword" onblur="check()">
<div id="div2" style="display:inline">
</div>
</td>
</tr>
<tr>
<td>
确认密码:
</td>
<td>
<input id="upassword1" type="password" name="upassword1" onblur="check()">
<div id="div3" style="display:inline">
</div>
</td>
</tr>
<tr>
<td>
电子邮件地址:
</td>
<td>
<input id="uemail" type="text" name="uemail" onblur="check()">
<div id="div4" style="display:inline">
</div>
</td>
</tr>
<tr align="center">
<td align="center">
<input type="submit" value="提交" name="tect6"><input type="reset" value="重置" name="text7">
</td>
</tr>
</table>
</form>
已经注册?马上去<a href="denglu.jsp">登陆</a>
</div>
</body>
</html>
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index_check.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
try{
String name=request.getParameter("uname");
String pass=request.getParameter("upassword");
String email=request.getParameter("uemail");
Class.forName("com.mysql.jdbc.Driver");
String url ="jdbc:mysql://localhost:3306/iod";
String username = "root";
String password = "123";
Connection conn = DriverManager.getConnection(url,username,password);
String sql="INSERT INTO user(uname, upassword,uemail) VALUES(?,?,?)";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, pass);
pstmt.setString(3, email);
int i=pstmt.executeUpdate();
if(i>0){
out.print("注册成功!1秒后跳到登陆页");
response.setHeader("refresh","1;url=denglu.jsp");
}
}
catch(Exception e){
out.print("注册失败");
e.printStackTrace();
}
%>
</body>
</html>
为什么总是提示注册失败,数据库也没添加成功。 --------------------编程问答-------------------- 看下异常信息。 --------------------编程问答-------------------- 没报错,知识直接跳到,注册失败页面 --------------------编程问答-------------------- 加断点,DEBUG一下。太长了 --------------------编程问答-------------------- 可以了,现在就是第一个界面报黄
补充:Java , Java相关