• 【JAVA程序设计】(C00087)基于Servlet+jsp的学生成绩管理系统


    项目简介

    基于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

    相关代码

    • Servlet代码
    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);
    	}
    
    }
    
    
    • 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
    • 成绩列表jsp代码
    <%@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>
    
    • 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

    运行截图

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  • 相关阅读:
    Linux安装MySQL8.0+及自启
    [论文翻译]Classical Probabilistic Models and Conditional Random Fields(下)
    【JavaScript—数组】详解js数组一篇文章吃透js-数组
    Himall商城- web私有方法
    SkeyeVSS视频安防综合管理系统助力智慧楼宇解决方案
    C专家编程 序
    Ramnit感染型病毒分析与处置
    Logger.error还不知道怎么传参打印?看完这个你就明白了
    图像相似度对比方法
    Hive的基本知识与操作
  • 原文地址:https://blog.csdn.net/mataodehtml/article/details/127750151