注册验证java代码[针对上篇文章]
时间:2020-02-02来源:系统城作者:电脑系统城
复制代码 代码如下:
<%@ 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>
相关信息
-
360安全卫士摄像头防护怎么设置为免打扰模式?
360安全卫士摄像头防护怎么设置为免打扰模式?电脑都安装了360安全卫士保护电脑,想要开启摄像头防护,该怎么操作呢?下面我们就来看看详细的教程,需要的朋友可以参考下...
2022-03-03
-
希沃管家开启冰点还原功能图文教程 希沃管家怎么用
希沃管家怎么用?希沃管家具有冰点原还功能,那么,我们该如何开启“冰点还原”功能呢?下文中为大家带来了希沃管家开启冰点还原功能图文教程。感兴趣的朋友不妨阅读下文内容,参考一下吧...
2022-03-03