studentList.jsp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <%@ page import="space.anyi.studentManageSystem_JSP.model.Student" %>
  3. <%@ page import="java.util.List" %>
  4. <html>
  5. <head>
  6. <title>学生管理系统 - 学生列表</title>
  7. <style>
  8. body {
  9. font-family: Arial, sans-serif;
  10. margin: 0;
  11. padding: 0;
  12. background-color: #f5f5f5;
  13. }
  14. .header {
  15. background-color: #007bff;
  16. color: white;
  17. padding: 20px;
  18. text-align: center;
  19. }
  20. .container {
  21. max-width: 1200px;
  22. margin: 20px auto;
  23. padding: 20px;
  24. background-color: white;
  25. border-radius: 8px;
  26. box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  27. }
  28. .search-form {
  29. margin-bottom: 20px;
  30. display: flex;
  31. gap: 10px;
  32. }
  33. .search-form input {
  34. flex: 1;
  35. padding: 8px;
  36. border: 1px solid #ddd;
  37. border-radius: 4px;
  38. }
  39. .btn {
  40. padding: 8px 16px;
  41. border: none;
  42. border-radius: 4px;
  43. cursor: pointer;
  44. text-decoration: none;
  45. display: inline-block;
  46. text-align: center;
  47. }
  48. .btn-primary {
  49. background-color: #007bff;
  50. color: white;
  51. }
  52. .btn-success {
  53. background-color: #28a745;
  54. color: white;
  55. }
  56. .btn-warning {
  57. background-color: #ffc107;
  58. color: black;
  59. }
  60. .btn-danger {
  61. background-color: #dc3545;
  62. color: white;
  63. }
  64. .btn:hover {
  65. opacity: 0.8;
  66. }
  67. .message {
  68. padding: 10px;
  69. margin-bottom: 20px;
  70. border-radius: 4px;
  71. text-align: center;
  72. }
  73. .success {
  74. background-color: #d4edda;
  75. color: #155724;
  76. border: 1px solid #c3e6cb;
  77. }
  78. .error {
  79. background-color: #f8d7da;
  80. color: #721c24;
  81. border: 1px solid #f5c6cb;
  82. }
  83. table {
  84. width: 100%;
  85. border-collapse: collapse;
  86. margin-top: 20px;
  87. }
  88. table th, table td {
  89. padding: 12px;
  90. text-align: left;
  91. border-bottom: 1px solid #ddd;
  92. }
  93. table th {
  94. background-color: #f8f9fa;
  95. font-weight: bold;
  96. }
  97. .actions {
  98. display: flex;
  99. gap: 5px;
  100. }
  101. .no-data {
  102. text-align: center;
  103. padding: 40px;
  104. color: #666;
  105. }
  106. </style>
  107. </head>
  108. <body>
  109. <div class="header">
  110. <h1>学生管理系统</h1>
  111. <div>
  112. <a href="${pageContext.request.contextPath}/student?action=add" class="btn btn-success">添加学生</a>
  113. <a href="${pageContext.request.contextPath}/logout" class="btn btn-danger" style="margin-left: 10px;">退出登录</a>
  114. </div>
  115. </div>
  116. <div class="container">
  117. <% if (request.getAttribute("message") != null) { %>
  118. <div class="message success">
  119. <%= request.getAttribute("message") %>
  120. </div>
  121. <% } %>
  122. <form class="search-form" action="${pageContext.request.contextPath}/student" method="get">
  123. <input type="hidden" name="action" value="search">
  124. <input type="text" name="name" placeholder="请输入学生姓名"
  125. value="<%= request.getAttribute("searchName") != null ? request.getAttribute("searchName") : "" %>">
  126. <button type="submit" class="btn btn-primary">搜索</button>
  127. <a href="${pageContext.request.contextPath}/student?action=list" class="btn">显示全部</a>
  128. </form>
  129. <%
  130. List<Student> students = (List<Student>) request.getAttribute("students");
  131. if (students != null && !students.isEmpty()) {
  132. %>
  133. <table>
  134. <thead>
  135. <tr>
  136. <th>ID</th>
  137. <th>姓名</th>
  138. <th>学号</th>
  139. <th>班级</th>
  140. <th>宿舍号</th>
  141. <th>联系方式</th>
  142. <th>操作</th>
  143. </tr>
  144. </thead>
  145. <tbody>
  146. <% for (Student student : students) { %>
  147. <tr>
  148. <td><%= student.getId() %></td>
  149. <td><%= student.getName() %></td>
  150. <td><%= student.getStudentId() %></td>
  151. <td><%= student.getClassName() %></td>
  152. <td><%= student.getDormitoryNumber() != null ? student.getDormitoryNumber() : "-" %></td>
  153. <td><%= student.getContact() != null ? student.getContact() : "-" %></td>
  154. <td class="actions">
  155. <a href="${pageContext.request.contextPath}/student?action=edit&id=<%= student.getId() %>"
  156. class="btn btn-warning">编辑</a>
  157. <a href="${pageContext.request.contextPath}/student?action=delete&id=<%= student.getId() %>"
  158. class="btn btn-danger"
  159. onclick="return confirm('确定要删除学生 <%= student.getName() %> 吗?')">删除</a>
  160. </td>
  161. </tr>
  162. <% } %>
  163. </tbody>
  164. </table>
  165. <% } else { %>
  166. <div class="no-data">
  167. <h3>暂无学生数据</h3>
  168. <p>点击"添加学生"按钮来添加第一条学生记录</p>
  169. </div>
  170. <% } %>
  171. </div>
  172. </body>
  173. </html>