-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.jsp
More file actions
71 lines (69 loc) · 2.35 KB
/
index.jsp
File metadata and controls
71 lines (69 loc) · 2.35 KB
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
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<title> Student Management System </title>
<link rel="stylesheet" href="mystyle.css"/>
</head>
<body>
<center>
<h1> Login Page 💻 </h1>
<br><br>
<a href="signup.jsp">
<button class="signup-button" type="submit" name="btn2">New Users</button>
<br>
</a>
<br><br>
<form method="POST">
<div class="name-container">
<input type="text" name="un" placeholder="enter username" required/>
<br><br>
<input type="password" name="pw" placeholder="enter password" required>
<br><br>
<button class="login-button" type="submit" name="btn">Login</button>
</div>
</form>
<%
if (request.getParameter("btn") != null)
{
String un = request.getParameter("un");
String pw = request.getParameter("pw");
try
{
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
String url = "jdbc:mysql://localhost:3306/sms_19july23";
Connection con = DriverManager.getConnection(url, "root", "amishaka");
String sql = "select * from user where un = ? and pw = ?";
PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, un);
pst.setString(2, pw);
ResultSet rs = pst.executeQuery();
if (rs.next()) {
session.setAttribute("un", un);
response.sendRedirect("sms.jsp");
} else {
%>
<script>
setTimeout(function() {
alert("Invalid login");
}, 10);
</script>
<%
}
con.close();
}
catch(SQLException e)
{
%>
<script>
setTimeout(function() {
alert("SQL issue: <%= e.getMessage() %>");
}, 10);
</script>
<%
}
}
%>
</center>
</body>
</html>