-
Notifications
You must be signed in to change notification settings - Fork 1
/
Valid.jsp
91 lines (72 loc) · 2.06 KB
/
Valid.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
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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>Insert title here</title>
<%!
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
public void jspInit(){
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/train","root","");
}
catch(Exception e ){
e.printStackTrace();
}
}
%>
</head>
<body>
<%
String email = "";
String pass = "";
try{
String sid = request.getSession().getId();
session.setAttribute("sid",sid);
email = request.getParameter("email");
pass = request.getParameter("pass");
String sql1 ="select user_id, author, uname from login where email=? and pass=?";
pstmt = con.prepareStatement(sql1);
pstmt.setString(1,email.trim());
pstmt.setString(2,pass.trim());
rs = pstmt.executeQuery();
String uname ="";
String author = "";
if(rs.next()){
uname = rs.getString("uname");
author = rs.getString("author");
String uid = rs.getString("user_id");
session.setAttribute("uname",uname);
session.setAttribute("uid",uid);
session.setAttribute("author",author);
session.setAttribute("error","N"); //User defined error name and value
if(rs.getString("author").equalsIgnoreCase("admin"))
{
response.sendRedirect("adminhome.jsp");
}
else if(rs.getString("author").equalsIgnoreCase("user"))
{
response.sendRedirect("userhome.jsp");
}
}
else{
session.setAttribute("error","Y"); //User defined error name and value
response.sendRedirect("home.jsp");
}
}
catch(Exception e){
e.printStackTrace();
session.setAttribute("error","Y");
response.sendRedirect("home.jsp");
}
%>
</body>
</html>