用jsp写一个教务系统
时间: 2023-10-31 10:04:15 浏览: 110
基于JSP的教务管理系统
4星 · 用户满意度95%
好的,以下是一个简单的教务管理系统的JSP页面示例,包括了学生列表和添加学生的功能:
1. 学生列表页面:studentList.jsp
```
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.example.model.Student" %>
<%@ page import="com.example.service.StudentService" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>学生管理系统</title>
</head>
<body>
<h1>学生列表</h1>
<table>
<thead>
<tr>
<th>学号</th>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<%
StudentService studentService = new StudentService();
List<Student> studentList = studentService.getStudentList();
for(Student student : studentList) {
%>
<tr>
<td><%= student.getStudentId() %></td>
<td><%= student.getName() %></td>
<td><%= student.getAge() %></td>
<td><%= student.getGender() %></td>
<td><a href="deleteStudent.jsp?id=<%= student.getId() %>">删除</a></td>
</tr>
<% } %>
</tbody>
</table>
<a href="addStudent.jsp">添加学生</a>
</body>
</html>
```
2. 添加学生页面:addStudent.jsp
```
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ page import="com.example.model.Student" %>
<%@ page import="com.example.service.StudentService" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>添加学生</title>
</head>
<body>
<h1>添加学生</h1>
<form method="post" action="addStudent.do">
<label>学号:</label>
<input type="text" name="studentId"/><br/>
<label>姓名:</label>
<input type="text" name="name"/><br/>
<label>年龄:</label>
<input type="text" name="age"/><br/>
<label>性别:</label>
<input type="radio" name="gender" value="男"/>男
<input type="radio" name="gender" value="女"/>女<br/>
<input type="submit" value="添加"/>
</form>
</body>
</html>
```
3. 添加学生的操作:addStudent.do
```
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ page import="com.example.model.Student" %>
<%@ page import="com.example.service.StudentService" %>
<%
String studentId = request.getParameter("studentId");
String name = request.getParameter("name");
int age = Integer.parseInt(request.getParameter("age"));
String gender = request.getParameter("gender");
Student student = new Student();
student.setStudentId(studentId);
student.setName(name);
student.setAge(age);
student.setGender(gender);
StudentService studentService = new StudentService();
studentService.addStudent(student);
response.sendRedirect("studentList.jsp");
%>
```
4. 删除学生的操作:deleteStudent.jsp
```
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ page import="com.example.service.StudentService" %>
<%
int id = Integer.parseInt(request.getParameter("id"));
StudentService studentService = new StudentService();
studentService.deleteStudentById(id);
response.sendRedirect("studentList.jsp");
%>
```
以上示例仅是一个简单的教务管理系统的JSP页面示例,仅供参考。实际的教务管理系统需要更加完善的功能和更健壮的代码实现。
阅读全文