-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzhuce.jsp
99 lines (97 loc) · 2.85 KB
/
zhuce.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<%@page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%
request.setCharacterEncoding("UTF-8");
Class.forName("com.mysql.jdbc.Driver");
Connection conn=
DriverManager.getConnection("jdbc:mysql://localhost:3306/zk2013150138?user=root&password=");
Statement stat=conn.createStatement();
%>
<html>
<head>
<title>注 册</title>
</head>
<body background="photo/yellowblue.jpg">
<%
int flag=0;
String ac1=request.getParameter("ac");
String pw1=request.getParameter("pw");
String na1=request.getParameter("na");
String ad1=request.getParameter("ad");
String ty=request.getParameter("atype");
String s;
if(ty.equals("stu"))
{s="select address from user where address='"+ad1+"'";}
else
{s="select address from teacher where address='"+ad1+"'";}
ResultSet rs=stat.executeQuery(s);
while(rs.next()){
String a=rs.getString("address");
if(a.equals(ad1)){flag=1;break;}
}//检测是否邮箱重复
if(ty.equals("stu"))
{s="select id from user where id='"+ac1+"'";}
else
{s="select id from teacher where id='"+ac1+"'";}
ResultSet rs1=stat.executeQuery(s);
while(rs1.next()){
String a1=rs1.getString("id");
if(a1.equals(ac1)){flag=1;break;}
}//检测是否账号重复
if(flag==1)
{%>
<p align="center"><font color="#297405" size="5">
<%out.println("该账号已被注册,请重新注册");%>
<br>页面将在3秒后自动跳转…………</font></p></font></p>
<script type="text/javascript">
window.setTimeout("time1()","3000");
function time1(){window.location.href="register.jsp";}
</script>
<%}
else{
if(ty.equals("stu")){
String sql="insert into user(id,name,address,password)values(?,?,?,?)";
PreparedStatement ps=conn.prepareStatement(sql);
ps.setString(1,ac1);
ps.setString(2,na1);
ps.setString(3,ad1);
ps.setString(4,pw1);
ps.executeUpdate();
ps.close();
%>
<p align="center"><font color="#297405" size="5">
<%out.println("类型学生,账号"+ac1+",邮箱"+ad1+",欢迎注册!");%>
<br>页面将在3秒后自动跳转…………</font></p></font></p>
</font></p>
<script type="text/javascript">
window.setTimeout("time2()","3000");
function time2(){window.location.href="index.jsp";}
</script>
<%
}
else
{
String sql1="insert into teacher(id,name,address,password)values(?,?,?,?)";
PreparedStatement ps1=conn.prepareStatement(sql1);
ps1.setString(1,ac1);
ps1.setString(2,na1);
ps1.setString(3,ad1);
ps1.setString(4,pw1);
ps1.executeUpdate();
ps1.close();
%>
<p align="center"><font color="#297405" size="5">
<%out.println("类型老师,账号"+ac1+",邮箱"+ad1+",欢迎注册!");%>
<br>页面将在3秒后自动跳转…………</font></p></font></p>
</font></p>
<script type="text/javascript">
window.setTimeout("time3()","3000");
function time3(){window.location.href="index.jsp";}
</script>
<%
}
}
conn.close();
%>
</body>
</html>