-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewProfile.jsp
More file actions
110 lines (101 loc) · 3.74 KB
/
viewProfile.jsp
File metadata and controls
110 lines (101 loc) · 3.74 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
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
100
101
102
103
104
105
106
107
108
109
110
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%
String email = (String) session.getAttribute("username");
String userId = "";
if (email == null) {
response.sendRedirect("index.html");
}
boolean userFound = false;
try {
// Database connection
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/LibraryDB", "root", "Mahadev07ji$");
// Query to fetch user details
String query = "SELECT id FROM Users WHERE email = ?";
PreparedStatement ps = con.prepareStatement(query);
ps.setString(1, email);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
userId = rs.getString("id");
userFound = true;
}
rs.close();
ps.close();
con.close();
} catch (Exception e) {
out.println("<h3>Error: " + e.getMessage() + "</h3>");
}
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>View Profile</title>
<link rel="stylesheet" href="dashboard.css">
<link rel="stylesheet" href="userStyle.css">
<style>
.toolbar .active {
background-color: #d9c8c8;
color: rgb(18, 18, 18);
border-radius: 10px;
}
</style>
</head>
<body>
<div class="toolbar">
<a href="userDashboard.jsp">Student Dashboard</a>
<a href="viewBooks.jsp">View Books</a>
<a href="searchBook.jsp">Search Book</a>
<a href="viewProfile.jsp">View Profile</a>
</div>
<div class="profile-container">
<h1>User Profile</h1>
<h2 style="color:antiquewhite; margin: 10px;">Books Issued:</h2>
<table>
<tr>
<th>Book ID</th>
<th>Title</th>
<th>Author</th>
<th>Borrow Date</th>
<th>Return Date</th>
</tr>
<%
// Replace with session or dynamic user ID
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/LibraryDB", "root", "Mahadev07ji$");
String query = "SELECT bb.book_id, b.title, b.author, bb.borrow_date, bb.return_date " +
"FROM borrowed_books bb " +
"JOIN books b ON bb.book_id = b.id " +
"WHERE bb.user_id = ?";
PreparedStatement ps = con.prepareStatement(query);
ps.setString(1, userId);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
int bookId = rs.getInt("book_id");
String title = rs.getString("title");
String author = rs.getString("author");
Date borrowDate = rs.getDate("borrow_date");
Date returnDate = rs.getDate("return_date");
out.println("<tr>");
out.println("<td>" + bookId + "</td>");
out.println("<td>" + title + "</td>");
out.println("<td>" + author + "</td>");
out.println("<td>" + borrowDate + "</td>");
out.println("<td>" + returnDate + "</td>");
out.println("</tr>");
}
rs.close();
ps.close();
con.close();
} catch (Exception e) {
out.println("<tr><td colspan='5'>Error: " + e.getMessage() + "</td></tr>");
}
%>
</table>
</div>
<script src="script.js"></script>
</body>
</html>