基于Servlet+jsp的学生成绩管理系统;
功能简单,适合学习以及大作业等,jsp页面,form表单提交数据
学生成绩的增删改查等功能;采用MVC设计模式JDBC连接数据库
运行环境:推荐jdk1.8;
开发工具:eclipse以及idea(推荐);
操作系统:windows 10 8G内存以上(其他windows以及macOS支持,但不推荐);
浏览器:Firefox(推荐)、Google Chrome(推荐)、Edge;
数据库:MySQL8.0(推荐)及其他版本(支持,但容易异常尤其MySQL5.7(不含)以下版本);
数据库可视化工具:Navicat Premium 15(推荐)以及其他Navicat版本
是否maven项目:否
后端:mysql、jdbc、servlet
前端:jsp
package servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import bean.Student;
import dao.StudentDao;
@WebServlet(name="/StudentServlet",urlPatterns="/student")
public class StudentServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");// 放在第一行
response.setCharacterEncoding("utf-8");
response.setContentType("text/html; charset=UTF-8");
String method = request.getParameter("method");
StudentDao ud = new StudentDao();
switch (method) {
case "delete":
Integer id = Integer.parseInt(request.getParameter("id"));
ud.delete(id);
response.sendRedirect("index.jsp");
break;
case "addPage":
request.getRequestDispatcher("add.jsp").forward(request, response);
break;
case "add":
add(request,response);
break;
case "editPage":
updatePage(request,response);
break;
case "update":
update(request,response);
break;
default:
break;
}
}
private void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String sno = request.getParameter("sno");
String name = request.getParameter("name");
String course = request.getParameter("course");
String grade = request.getParameter("grade");
Integer id = Integer.parseInt(request.getParameter("id"));
Student stu = new Student();
stu.setId(id);
stu.setName(name);
stu.setCourse(course);
stu.setGrade(grade);
stu.setSno(sno);
StudentDao ud = new StudentDao();
ud.update(stu, id);
response.sendRedirect("index.jsp");
}
private void updatePage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
int id = Integer.parseInt(request.getParameter("id"));
StudentDao ud = new StudentDao();
Student stu = ud.getById(id);
request.setAttribute("stu",stu);
request.getRequestDispatcher("updata.jsp").forward(request, response);
}
private void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String sno = request.getParameter("sno");
String name = request.getParameter("name");
String course = request.getParameter("course");
String grade = request.getParameter("grade");
Student stu = new Student();
stu.setName(name);
stu.setCourse(course);
stu.setGrade(grade);
stu.setSno(sno);
StudentDao ud = new StudentDao();
ud.add(stu);
response.sendRedirect("index.jsp");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
<%@page import="bean.Student"%>
<%@page import="java.util.List"%>
<%@page import="dao.StudentDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title heretitle>
head>
<body>
<%
StudentDao ud = new StudentDao();
List<Student> list = ud.getAllByPage();
request.setAttribute("list", list);
%>
<div>
<button onClick="location.href='student?method=addPage'">新增button>
div>
<table cellspacing="0" width="500px" border="1px" style="text-align: center">
<thead>
<tr>
<th>序号th>
<th>学号th>
<th>姓名th>
<th>课程th>
<th>成绩th>
<th>操作th>
tr>
thead>
<tbody>
<c:forEach items="${list}" var="item" varStatus="i" >
<tr>
<td>${i.index+1 }td>
<td>${item.sno}td>
<td>${item.name}td>
<td>${item.course}td>
<td>${item.grade}td>
<td>
<a href="student?method=editPage&id=${item.id}">修改a>
<a href="student?method=delete&id=${item.id}">删除a>
td>
tr>
c:forEach>
tbody>
table>
body>
html>