51,409
社区成员
发帖
与我相关
我的任务
分享
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%
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>register!</title>
</head>
<body>
<form action="registerDeal.jsp">
用户名:<input type="text" name="username"><br>
密 码:<input type="password" name="password"><br>
重复密码:<input type="password" name="password2"><br>
<input type="submit" value="提交">
</form>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%@ page import="java.sql.*" %>
<%
String username=request.getParameter("username");
String password=request.getParameter("password");
String password2=request.getParameter("password2");
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/register","root","12345");
String sqlQuery="select count(*) from user where username=?";
PreparedStatement psQuery=conn.prepareStatement(sqlQuery);
psQuery.setString(1,username);
ResultSet rs=psQuery.executeQuery();
rs.next();
int count=rs.getInt(1);
if(count>0){
rs.close();psQuery.close();conn.close();
response.sendRedirect("registerFail.jsp");
return;
}
String sql="insert into user values(null,?,?)";
PreparedStatement ps=conn.prepareStatement(sql);
ps.setString(1,username);
ps.setString(2,password);
ps.executeUpdate();
ps.close();conn.close();
response.sendRedirect("registerSuccess.jsp");
%>
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%
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>register!</title>
</head>
<body>
Success! <br>
</body>
</html>
registerFail.jsp
[code=Java]
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%
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>register!</title>
</head>
<body>
Fail!<br>
</body>
</html>