-
Notifications
You must be signed in to change notification settings - Fork 0
/
logToInd.jsp
59 lines (49 loc) · 1.45 KB
/
logToInd.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
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import = "java.sql.*" %>
<%@ page import = "javax.sql.*" %>
<%@ page import = "java.io.IOException" %>
<!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=ISO-8859-1">
<title>LogtoIndex</title>
</head>
<body>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
session.removeAttribute("msg");
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/trade", "root", "");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM users");
boolean uflag = false;
boolean pflag = false;
while (rs.next())
{
if (username.equals(rs.getString("username")))
{
uflag = true;
if (password.equals(rs.getString("password")))
{
pflag = true;
session.setAttribute("uname", username);
response.sendRedirect("index.jsp");
break;
}
}
}
if (uflag == false)
{
session.setAttribute("msg", "user not exist");
response.sendRedirect("login.jsp");
}
if (uflag == true && pflag == false)
{
session.setAttribute("msg", "wrong password");
response.sendRedirect("login.jsp");
}
%>
</body>
</html>