注冊驗證java代碼[針對上篇文章]

 更新時間:2009年08月29日 01:02:30   作者:  
注冊驗證代碼[針對上篇文章] ,大家可以多參考腳本之家以前發布的文章。
http://www.dreamboatsglobal.com/article/19801.htm
復制代碼 代碼如下:

<%@ page contentType="text/html; charset=gb2312" language="java"%>
<%@ page import="java.sql.*"%>
<!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>
</head>
<body>
<%
String strSql="";
String database_username="root";
String database_password="";
String url="jdbc:mysql://localhost/ch3?useUnicode=true&characterEncoding=gb2312";
try
{
Class.forName("org.gjt.mm.mysql.Driver");
Connection dbConn= DriverManager.getConnection(url,database_username,database_password);
Statement stmt=dbConn.createStatement();
ResultSet rs=null;
String s_UserName = request.getParameter("UserName");
strSql = "select * from users where UserName like '"+s_UserName+"'";
rs = stmt.executeQuery(strSql);
if(rs.next())
{
out.println("<h1 align=center>用戶名<font color=red>"+s_UserName+"</font>已經存在!</h1>");
out.println("<div align=center><input type=button name=btn value=返回 onClick='window.history.go(-1)'></div>");
}
else
{
String s_UserPassword = request.getParameter("UserPassword");
String s_NickName = request.getParameter("NickName");
String s_Sex = request.getParameter("Sex");
String s_Email = request.getParameter("Email");
strSql = "insert into users (UserName,UserPassword,NickName,Sex,Email) values('"+s_UserName+"','"+s_UserPassword+"','"+s_NickName+"','"+s_Sex+"','"+s_Email+"')";
try
{
stmt.executeUpdate(strSql);
out.println("<h1 align=center>用戶注冊成功,您的注冊信息如下</h1>");
out.println("<p align=center>用戶名:<font color=blue>"+s_UserName+"</font></p>");
out.println("<p align=center>密碼:<font color=blue>"+s_UserPassword+"</font></p>");
out.println("<p align=center>昵稱:<font color=blue>"+s_NickName+"</font></p>");
if(s_Sex.equals("0"))
{
out.println("<p align=center>性別:<font color=blue>男</font></p>");
}
else
{
out.println("<p align=center>性別:<font color=blue>女</font></p>");
}
out.println("<p align=center>Email:<font color=blue>"+s_Email+"</font></p>");
}
catch(Exception ex)
{
out.println("<h1 align=center>用戶注冊失敗</h1>");
out.println("<div align=center><input type=button name=btn1 value=返回 onClick='window.history.go(-1)'></div>");
}
}
rs.close();
stmt.close();
dbConn.close();
}
catch(Exception ex)
{
out.println("<h1 align=center>數據庫連接錯誤</h1>");
out.println("<div align=center><input type=button name=btn2 value=返回 onClick='window.history.go(-1)'></div>");
}
%>
</body>
</html>

相關文章

最新評論

免费人成视频在线观看