-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyNotes.jsp
142 lines (125 loc) · 3.44 KB
/
myNotes.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<%--
Document : myNotes
Created on : 8 Oct 2024, 9:52:02 pm
Author : anama
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My Notes</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
table {
width: 80%;
border-collapse: collapse;
margin: 20px auto; /* Center the table */
}
th, td {
padding: 10px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #1d3bb8;
color: white;
}
.nav {
display: flex;
justify-content: space-between;
align-items: center;
background-color: white;
padding: 10px 20px;
margin-top: 20px;
margin-left: 300px;
margin-right: 300px;
}
.nav-left h1 {
color: #333;
font-size: 24px;
}
.nav-right a {
color: #333;
text-decoration: none;
margin-left: 20px;
font-size: 16px;
}
.nav-right .signup-btn {
border: 2px solid #838485;
padding: 5px 15px;
border-radius: 5px;
background-color: transparent;
transition: background-color 0.3s ease, color 0.3s ease;
}
.nav-right .signup-btn:hover {
background-color: #333;
color: white;
}
</style>
</head>
<body>
<nav class="nav">
<div class="nav-left">
<h1>NoteHub</h1>
</div>
<div class="nav-right">
<a href="groups.jsp">MyGroups</a>
<a href="uploadNote.jsp">Upload</a>
<a href="myNotes.jsp">My Notes</a>
<a href="profile.jsp" class="signup-btn">Profile</a>
</div>
</nav>
<table>
<tr>
<th>Title</th>
<th>Uploaded On</th>
<th>Group Name</th>
<th>File</th>
</tr>
<%
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
int userId = (Integer) session.getAttribute("userId");
String sql = "SELECT title, updated_at, group_name, file_path FROM notes WHERE user_id = ?";
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/project", "root", "");
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setInt(1, userId);
rs = pstmt.executeQuery();
while (rs.next()) {
String noteTitle = rs.getString("title");
String uploaded = rs.getString("updated_at");
String group = rs.getString("group_name");
String filePath = rs.getString("file_path");
%>
<tr>
<td><%= noteTitle %></td>
<td><%= uploaded %></td>
<td><%= group %></td>
<td><a href="<%= filePath %>">Download</a></td>
</tr>
<%
}
} catch (Exception e) {
out.println("Error retrieving notes: " + e.getMessage());
} finally {
try {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (con != null) con.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
%>
</table>
</body>
</html>