精华内容
下载资源
问答
  • java作业学生成绩管理系统(控制台实现),适合刚学习java面向对象的同学
  • 学生成绩管理系统(SSMS),涉及到学生、教师、系统管理员、班级、学生成绩、课程。设置一个系统管理员对系统进行管理。该系统分为三大类:管理员、学生、教师。该项目是基于javaweb进行开发,很适合刚学完javaweb的...
  • 学生成绩管理系统.zip

    2020-04-29 21:36:44
    学生成绩管理系统,分为老师、学生和管理员三个角色,管理员管理系统,教师登记成绩,学生查看成绩等,有源码和sql文件
  • 系统分为三个角色,分别是学生,老师,管理员。管理员可以对学生和老师的信息进行增删改查,老师可以对学生录入成绩,学生可以查看自己的成绩。界面美观大方,技术不复杂。 运行环境 jdk8+tomcat8+mysql+IDEA
  • 根据IDEA完成的简单学生成绩管理系统 要求:输入选项,当选择录入成绩的时候来输入各个学生的成绩,直到输入(-1)结束输入成绩,最后输出输入了几名学生的成绩,然后循环到主界面,输入其他的选项,来查询学生成绩...

    根据IDEA完成的简单学生成绩管理系统

    要求:输入选项,当选择录入成绩的时候来输入各个学生的成绩,直到输入(-1)结束输入成绩,最后输出输入了几名学生的成绩,然后循环到主界面,输入其他的选项,来查询学生成绩的平均分,最高分,最低分,然后退出系统。

    1、主界面

    在这里插入图片描述

    System.out.println("----学生成绩管理系统----");
                System.out.println("1.录入成绩");
                System.out.println("2.平均分");
                System.out.println("3.最高分");
                System.out.println("4.最低分");
                System.out.println("5.退出系统");
                System.out.println("请选择:");
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
    

    2、录入成绩

    在这里插入图片描述

    if (n == 1) {
                    while (true) {
                        System.out.println("请输入学生成绩:");
                        int score = sc.nextInt();
                        if (score == -1) {
                            break;
                        }
                        max = Math.max(score, max);
                        min = Math.min(score, min);
                        sum = sum + score;
                        count++;
                    }
                    System.out.println("你一共输入了" + count + "个学生的成绩");
                }
    

    3、平均分

    在这里插入图片描述

    if (n == 2) {
                    int avg = sum == 0 ? 0 : sum / count;
                    System.out.println("平均分" + avg);
                }
    

    4、最高分

    在这里插入图片描述

    if (n == 3) {
                    System.out.println("最高分" + max);
                }
    

    5、最低分

    在这里插入图片描述

    if (n == 4) {
                    System.out.println("最低分" + min);
                }
    

    6、退出系统

    在这里插入图片描述

    if (n == 5) {
                    System.out.println("谢谢使用,再见!");
                    break;
                }
    

    6、总结

    因为每次输出都要退出循环,所以需要用到while。
    在这里把整体的所有代码都copy过来。

    int count = 0;
            int max = -1;
            int min = 101;
            int sum = 0;
            while (true) {
                System.out.println("----学生成绩管理系统----");
                System.out.println("1.录入成绩");
                System.out.println("2.平均分");
                System.out.println("3.最高分");
                System.out.println("4.最低分");
                System.out.println("5.退出系统");
                System.out.println("请选择:");
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                if (n == 1) {
                    while (true) {
                        System.out.println("请输入学生成绩:");
                        int score = sc.nextInt();
                        if (score == -1) {
                            break;
                        }
                        max = Math.max(score, max);
                        min = Math.min(score, min);
                        sum = sum + score;
                        count++;
                    }
                    System.out.println("你一共输入了" + count + "个学生的成绩");
                }
                if (n == 2) {
                    int avg = sum == 0 ? 0 : sum / count;
                    System.out.println("平均分" + avg);
                }
                if (n == 3) {
                    System.out.println("最高分" + max);
                }
                if (n == 4) {
                    System.out.println("最低分" + min);
                }
                if (n == 5) {
                    System.out.println("谢谢使用,再见!");
                    break;
                }
            }
    

    本系统的问题

    如果没有录入成绩直接选择平均分、最高分或者最低分,会出现程序报错,或者数值不对。
    在这里插入图片描述
    由于本次时间有限,下次再跟大家整理更新如何避免这个问题。

    另外各位有什么想法也可以评论在下方,大家共同交流进步!!!谢谢大家!

    展开全文
  • 主要为大家详细介绍了Java GUI实现学生成绩管理系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
  • JavaWeb系统系列实现 Java+JSP实现学生图书管理系统 Java+JSP实现学生信息管理系统 Java+JSP实现用户信息管理系统 Java+Servlet+JSP实现航空订票...Java+Servlet+JSP实现学生成绩管理系统-1 Java+Servlet+JSP实

    目录

    一、系统介绍

    1.开发环境

    2.技术选型

    3.系统功能

    4.数据库

    5.工程截图

    二、系统展示 

    1.登录系统

    2.学生-主页面

    3.学生-我的成绩

    4.学生-修改密码

    5.教师-主页面

    6.教师-录入成绩

    7.教师-修改密码

    8.管理员-主页面

    9.管理员-学生管理-增加学生

    10.管理员--学生管理-管理学生

    11.管理员-老师管理-增加老师

    12.管理员-老师管理-管理老师

    三、部分代码

    AdminController

    HrefController

    LoginController

    StudentController

    TeachController

    四、其他

    1.其他系统实现

    1.JavaWeb系统系列实现

    2.JavaSwing系统系列实现

    2.获取源码

    3.运行项目

    4.备注

    5.支持博主


    JavaWeb系统系列实现

    Java+JSP实现学生图书管理系统

    Java+JSP实现学生信息管理系统

    Java+JSP实现用户信息管理系统

    Java+Servlet+JSP实现航空订票系统

    Java+Servlet+JSP实现新闻发布系统

    Java+Servlet+JSP学生宿舍管理系统

    Java+Servlet+JSP实现图书管理系统

    Java+Servlet+JSP实现学生信息管理系统

    Java+Servlet+JSP实现学生选课管理系统

    Java+Servlet+JSP实现学生成绩管理系统-1

    Java+Servlet+JSP实现学生成绩管理系统-2

    Java+Servlet+JSP实现宠物诊所管理系统

    Java+SSM+JSP实现网上考试系统

    Java+SSH+JSP实现在线考试系统

    Java+SSH+JSP实现医院在线挂号系统

    Java+Springboot+Mybatis+Bootstrap+Maven实现网上商城系统

    一、系统介绍

    1.开发环境

    开发工具:IDEA2018.2

    JDK版本:jdk1.8

    Mysql版本:8.0.13

    2.技术选型

    后端:Java+Spring+SpringMVC+Mybatis。

    前端:Layui+JSP+HTML+CSS。

    3.系统功能

    登录系统

    1.学生

    我的成绩:查看个人的成绩。

    修改密码:修改系统登录密码。

    2.教师

    录入成绩:录入和修改学生成绩。

    修改密码:修改系统登录密码。

    3.管理员

    学生管理:对学生信息进行增删改查。

    教师管理:对教师信息进行增删改查。

    4.数据库

    /*
     Navicat Premium Data Transfer
    
     Source Server         : MySQL
     Source Server Type    : MySQL
     Source Server Version : 80013
     Source Host           : 127.0.0.1:3306
     Source Schema         : ssm_score
    
     Target Server Type    : MySQL
     Target Server Version : 80013
     File Encoding         : 65001
    
     Date: 01/09/2021 21:45:11
    */
    
    SET NAMES utf8mb4;
    SET FOREIGN_KEY_CHECKS = 0;
    
    -- ----------------------------
    -- Table structure for admin
    -- ----------------------------
    DROP TABLE IF EXISTS `admin`;
    CREATE TABLE `admin`  (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `username` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
      `password` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
      PRIMARY KEY (`id`) USING BTREE
    ) ENGINE = MyISAM AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic;
    
    -- ----------------------------
    -- Records of admin
    -- ----------------------------
    INSERT INTO `admin` VALUES (1, 'admin', 'admin');
    
    -- ----------------------------
    -- Table structure for student
    -- ----------------------------
    DROP TABLE IF EXISTS `student`;
    CREATE TABLE `student`  (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `username` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
      `password` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
      `stuclass` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
      `stuname` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
      `stuno` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
      `score` double NULL DEFAULT NULL,
      PRIMARY KEY (`id`) USING BTREE
    ) ENGINE = MyISAM AUTO_INCREMENT = 22 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic;
    
    -- ----------------------------
    -- Records of student
    -- ----------------------------
    INSERT INTO `student` VALUES (8, 'a', '123456', '1702', '乔乔丫', '1700130222', 1000);
    INSERT INTO `student` VALUES (9, 'b', '123456', '1702', '周瑜', '1700130223', 100);
    INSERT INTO `student` VALUES (10, 'c', '123456', '1703', '曹操', '1700130224', 6);
    INSERT INTO `student` VALUES (11, 'd', '123456', '1704', '小美', '1700130225', 90);
    INSERT INTO `student` VALUES (12, 'e', '123456', '1701', '王菲', '1700130226', 100);
    INSERT INTO `student` VALUES (13, 'f', '123456', '1703', '周杰伦', '1700130227', NULL);
    
    -- ----------------------------
    -- Table structure for teacher
    -- ----------------------------
    DROP TABLE IF EXISTS `teacher`;
    CREATE TABLE `teacher`  (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `username` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
      `password` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
      `teaname` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
      PRIMARY KEY (`id`) USING BTREE
    ) ENGINE = MyISAM AUTO_INCREMENT = 9 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic;
    
    -- ----------------------------
    -- Records of teacher
    -- ----------------------------
    INSERT INTO `teacher` VALUES (3, 'root', '123456', '李老师');
    INSERT INTO `teacher` VALUES (7, 'a', '123456', '孟老师');
    INSERT INTO `teacher` VALUES (5, 'b', '123456', '赵老师');
    INSERT INTO `teacher` VALUES (6, 'c', '123456', '李老师');
    
    SET FOREIGN_KEY_CHECKS = 1;
    

    5.工程截图

    二、系统展示 

    1.登录系统

    2.学生-主页面

    3.学生-我的成绩

    4.学生-修改密码

    5.教师-主页面

    6.教师-录入成绩

    7.教师-修改密码

    8.管理员-主页面

    9.管理员-学生管理-增加学生

    10.管理员--学生管理-管理学生

    11.管理员-老师管理-增加老师

    12.管理员-老师管理-管理老师

    三、部分代码

    AdminController

    package com.hhtc.controller;
    import java.util.List;
    import javax.servlet.http.HttpSession;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
    import org.springframework.web.servlet.ModelAndView;
    
    import com.hhtc.po.Page;
    import com.hhtc.po.Student;
    import com.hhtc.po.Teacher;
    import com.hhtc.service.AdminService;
    
    import net.sf.json.JSONArray;
    import net.sf.json.JSONObject;
    @Controller
    public class AdminController {
    	@Autowired
    		private AdminService adminService;
    	@RequestMapping("/welcome")
    	public ModelAndView welcome(Model model) {
    		ModelAndView mav = new ModelAndView("admin/welcome");
    		return mav;
    	}
    	//学生
    		//学生数据分页
    		@RequestMapping(value = "/liststudent",method = {RequestMethod.POST, RequestMethod.GET},produces ="application/json;charset=UTF-8")
    		@ResponseBody
    		public String liststudent(Page page) {
    			List<Student> list=adminService.stumanage();
    			page.caculatestart();
    			List<Student> list2=adminService.liststudent(page);
    			JSONObject jsonobj=new JSONObject();
    			jsonobj.put("code", 0);
    			jsonobj.put("msg", "成功");
    			jsonobj.put("count",list.size());
    			JSONArray jsonobj2=new JSONArray();
    			JSONObject jsonobj3=new JSONObject();
    		    for(Student student:list2) {
    		    	jsonobj3.put("id",student.getId());
    		    	jsonobj3.put("username",student.getUsername());
    		    	jsonobj3.put("password",student.getPassword());
    		    	jsonobj3.put("stuclass",student.getStuclass());
    		    	jsonobj3.put("stuname",student.getStuname());
    		    	jsonobj3.put("stuno",student.getStuno());
    		    	jsonobj2.add(jsonobj3);
    		    }
    		    jsonobj.put("data", jsonobj2);		
    			return jsonobj.toString();
    		}
    		@RequestMapping("/addstudent")
    		public ModelAndView addstu(Student student,Model model) {
    			adminService.addStudent(student);
    			ModelAndView mav = new ModelAndView("admin/stumanage");
    			return mav;
    		}
    		@RequestMapping("/delstu")
    		public ModelAndView delstu(String id,Model model) {
    			adminService.delstudnet(id);
    			ModelAndView mav = new ModelAndView("admin/stumanage");
    			return mav;
    		}
    		@RequestMapping("/updatestu")
    		public ModelAndView updatestu(String id,Student student,Model model) {
    			student.setId(Integer.parseInt(id));
    			adminService.updatestu(student);
    			ModelAndView mav = new ModelAndView("admin/stumanage");
    			return mav;
    		}
    		@RequestMapping(value = "/mohuname",method = {RequestMethod.POST, RequestMethod.GET},produces ="application/json;charset=UTF-8")
    		@ResponseBody
    		public String mohuname(HttpSession session) {
    			@SuppressWarnings("unchecked")
    			List<Student> list=(List<Student>) session.getAttribute("list");
    			JSONObject jsonobj=new JSONObject();
    			jsonobj.put("code", 0);
    			jsonobj.put("msg", "成功");
    			jsonobj.put("count",list.size());
    			JSONArray jsonobj2=new JSONArray();
    			JSONObject jsonobj3=new JSONObject();
    		    for(Student student:list) {
    		    	jsonobj3.put("id",student.getId());
    		    	jsonobj3.put("username",student.getUsername());
    		    	jsonobj3.put("password",student.getPassword());
    		    	jsonobj3.put("stuclass",student.getStuclass());
    		    	jsonobj3.put("stuname",student.getStuname());
    		    	jsonobj3.put("stuno",student.getStuno());
    		    	jsonobj2.add(jsonobj3);
    		    }
    		    jsonobj.put("data", jsonobj2);		
    			return jsonobj.toString();
    		}
    	//老师
    		@RequestMapping("/addtea")
    		public ModelAndView addteacher(Teacher teacher,Model model) {
    			adminService.addteacher(teacher);
    			ModelAndView mav = new ModelAndView("admin/teamanage");
    			return mav;
    		}
    		@RequestMapping(value = "/teamanage",method = {RequestMethod.POST, RequestMethod.GET},produces ="application/json;charset=UTF-8")
    		@ResponseBody
    		public String teamanage(Model model) {
    			List<Teacher> list=adminService.teamanage();
    			JSONObject jsonobj=new JSONObject();
    			jsonobj.put("code", 0);
    			jsonobj.put("msg", "成功");
    			jsonobj.put("count",list.size());
    			JSONArray jsonobj2=new JSONArray();
    			JSONObject jsonobj3=new JSONObject();
    		    for(Teacher teacher:list) {
    		    	jsonobj3.put("id",teacher.getId());
    		    	jsonobj3.put("username",teacher.getUsername());
    		    	jsonobj3.put("password",teacher.getPassword());
    		    	jsonobj3.put("teaname",teacher.getTeaname());
    		    	jsonobj2.add(jsonobj3);
    		    }
    		    jsonobj.put("data", jsonobj2);		
    			return jsonobj.toString();
    		}
    		@RequestMapping("/deltea")
    		public ModelAndView deltea(String id,Model model) {
    			adminService.delteacher(id);
    			ModelAndView mav = new ModelAndView("admin/teamanage");
    			return mav;
    		}
    		@RequestMapping("/updatetea")
    		public ModelAndView updatetea(String id,Teacher teacher,Model model) {
    			teacher.setId(Integer.parseInt(id));
    			adminService.updatetea(teacher);
    			ModelAndView mav = new ModelAndView("admin/teamanage");
    			return mav;
    		}
    		@RequestMapping(value = "/mohunametea",method = {RequestMethod.POST, RequestMethod.GET},produces ="application/json;charset=UTF-8")
    		@ResponseBody
    		public String mohunametea(HttpSession session) {
    			@SuppressWarnings("unchecked")
    			List<Teacher> list=(List<Teacher>) session.getAttribute("tealist");
    			JSONObject jsonobj=new JSONObject();
    			jsonobj.put("code", 0);
    			jsonobj.put("msg", "成功");
    			jsonobj.put("count",list.size());
    			JSONArray jsonobj2=new JSONArray();
    			JSONObject jsonobj3=new JSONObject();
    		    for(Teacher teacher:list) {
    		    	jsonobj3.put("id",teacher.getId());
    		    	jsonobj3.put("username",teacher.getUsername());
    		    	jsonobj3.put("password",teacher.getPassword());
    		    	jsonobj3.put("teaname",teacher.getTeaname());
    		    	jsonobj2.add(jsonobj3);
    		    }
    		    jsonobj.put("data", jsonobj2);		
    			return jsonobj.toString();
    		}
    }
    


    HrefController

    package com.hhtc.controller;
    import java.util.List;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.servlet.ModelAndView;
    
    import com.hhtc.po.Student;
    import com.hhtc.po.Teacher;
    import com.hhtc.service.AdminService;
    @Controller
    public class HrefController {
    	@Autowired
    	private AdminService adminService;
    	@RequestMapping("/index")
    	public ModelAndView index(Model model) {
    		ModelAndView mav = new ModelAndView("index");
    		return mav;
    	}
    	//学生
    	@RequestMapping("/hrefaddstu")
    	public ModelAndView addstu(Model model) {
    		ModelAndView mav = new ModelAndView("admin/addstu");
    		return mav;
    	}
    	@RequestMapping("/hrefmohuname")
    	public ModelAndView hrefmohuname(String stuname,Model model,HttpSession session) {
    		List<Student> list=adminService.selectbyname(stuname);
    		session.setAttribute("list", list);
    		ModelAndView mav = new ModelAndView("admin/mohuname");
    		return mav;
    	}
    	@RequestMapping("/hrefxiustu")
    	public String xiustu(String id,Model model) {
    		Student student=adminService.selectone(id);
    		model.addAttribute("student",student);
    		return "admin/updatestu";
    	}
    	@RequestMapping("/hrefstumanage")
    	public ModelAndView hrefstumanage(Model model) {
    		ModelAndView mav = new ModelAndView("admin/stumanage");
    		return mav;
    	}
    //老师
    	@RequestMapping("/hrefaddtea")
    	public ModelAndView hrefaddtea(Model model) {
    		ModelAndView mav = new ModelAndView("admin/addtea");
    		return mav;
    	}
    	@RequestMapping("/hrefteamanage")
    	public ModelAndView hrefteamanage(Model model) {
    		ModelAndView mav = new ModelAndView("admin/teamanage");
    		return mav;
    	}
    	@RequestMapping("/hrefmohunametea")
    	public ModelAndView hrefmohunametea(String teaname,Model model,HttpSession session) {
    		List<Teacher> list=adminService.selectbynametea(teaname);
    		session.setAttribute("tealist",list);
    		ModelAndView mav = new ModelAndView("admin/mohuname2");
    		return mav;
    	}
    	@RequestMapping("/hrefxiutea")
    	public String hrefxiutea(String id,Model model) {
    		Teacher teacher=adminService.selectonetea(id);
    		model.addAttribute("teacher",teacher);
    		return "admin/updatetea";
    	}
    }
    


    LoginController

    package com.hhtc.controller;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.servlet.ModelAndView;
    
    import com.hhtc.po.Admin;
    import com.hhtc.po.Student;
    import com.hhtc.po.Teacher;
    import com.hhtc.service.LoginService;
    @Controller
    public class LoginController {
    	@Autowired
    	private LoginService loginService;	
    	@RequestMapping("/login")
    	public ModelAndView findCustomerById(String username,String password,String people,Model model,HttpSession session) {
    		if("student".equals(people)) {
    			Student student=new Student();
    			student.setUsername(username);
    			student.setPassword(password);
    			Student student2=loginService.findStuTeachByUsername(student);
    			if(student2!=null) {
    				session.setAttribute("student", student2);
    				ModelAndView mav = new ModelAndView("/student/indexs");
    				return mav;
    			}else {
    				ModelAndView mav = new ModelAndView("error");
    				return mav;
    			}
    		}else if("teacher".equals(people)){
    			Teacher teacher=new Teacher();
    			teacher.setUsername(username);
    			teacher.setPassword(password);
    			Teacher teacher2=loginService.findTeachByUsername(teacher);
    			if(teacher2!=null) {
    				session.setAttribute("teacher", teacher2);
    				ModelAndView mav = new ModelAndView("/teacher/indext");
    				return mav;
    			}else {
    				ModelAndView mav = new ModelAndView("error");
    				return mav;
    			}
    		}else if("manage".equals(people)){
    			Admin admin =new Admin();
    			admin.setUsername(username);
    			admin.setPassword(password);
    			if(loginService.findAdminById(admin)!=null) {
    				ModelAndView mav = new ModelAndView("/admin/index");
    				return mav;
    			}else {
    				ModelAndView mav = new ModelAndView("error");
    				return mav;
    			}
    		}
    		ModelAndView mav = new ModelAndView("error");
    		return mav;
    	}
    	@RequestMapping("/out")
    	public ModelAndView out(HttpServletResponse response,HttpSession session,Model model) {
    		ModelAndView mav = new ModelAndView("index");
    		return mav;
    	}
    }
    


    StudentController

    package com.hhtc.controller;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.servlet.ModelAndView;
    
    import com.hhtc.po.Student;
    import com.hhtc.service.GeneraService;
    @Controller
    public class StudentController {
    	@Autowired
    	private GeneraService generaService;
    	//学生
    	@RequestMapping("/hrefstuinfo")
    	public ModelAndView hrefstuinfo(Model model) {
    		ModelAndView mav = new ModelAndView("student/stuinfo");
    		return mav;
    	}
    	@RequestMapping("/hrefupdatepws")
    	public ModelAndView hrefupdatepws(Model model) {
    		ModelAndView mav = new ModelAndView("student/updatepws");
    		return mav;
    	}
    	@RequestMapping("/updatepws")
    	public ModelAndView updatepws(Student student,Model model) {
    		this.generaService.updatepws(student);
    		ModelAndView mav = new ModelAndView("success");
    		return mav;
    	}
    }
    


    TeachController

    package com.hhtc.controller;
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
    import org.springframework.web.servlet.ModelAndView;
    
    import com.hhtc.po.Page;
    import com.hhtc.po.Student;
    import com.hhtc.po.Teacher;
    import com.hhtc.service.AdminService;
    import com.hhtc.service.GeneraService;
    
    import net.sf.json.JSONArray;
    import net.sf.json.JSONObject;
    @Controller
    public class TeachController {
    	@Autowired
    	private AdminService adminService;
    	@Autowired
    	private GeneraService generaService;
    	@RequestMapping("/hrefaddscore")
    	public ModelAndView hrefaddscore(Model model) {
    		ModelAndView mav = new ModelAndView("teacher/addscore");
    		return mav;
    	}
    	@RequestMapping("/hrefupdatepw")
    	public ModelAndView hrefupdatepw(Model model) {
    		ModelAndView mav = new ModelAndView("teacher/updatepw");
    		return mav;
    	}
    	@RequestMapping(value = "/stuscore",method = {RequestMethod.POST, RequestMethod.GET},produces ="application/json;charset=UTF-8")
    	@ResponseBody
    	public String stuscoree(Page page,Model model) {
    		List<Student> list=adminService.stumanage();
    		page.caculatestart();
    		List<Student> list2=adminService.liststudent(page);
    		JSONObject jsonobj=new JSONObject();
    		jsonobj.put("code", 0);
    		jsonobj.put("msg", "成功");
    		jsonobj.put("count",list.size());
    		JSONArray jsonobj2=new JSONArray();
    		JSONObject jsonobj3=new JSONObject();
    	    for(Student student:list2) {
    	    	jsonobj3.put("id",student.getId());
    	    	jsonobj3.put("stuno", student.getStuno());
    	    	jsonobj3.put("stuname",student.getStuname());
    	    	jsonobj3.put("stuclass",student.getStuclass());
    	    	jsonobj3.put("score",student.getScore());    	
    	    	jsonobj2.add(jsonobj3);
    	    }
    	    jsonobj.put("data", jsonobj2);		
    		return jsonobj.toString();
    	}
    	@RequestMapping("/updatepw")
    	public ModelAndView updatepw(Teacher teacher,Model model) {
    		this.generaService.updatepw(teacher);
    		ModelAndView mav = new ModelAndView("success");
    		return mav;
    	}
    	@RequestMapping("/updatescore")
    	public ModelAndView updatescore(String id,String score,Model model) {
    		Student student=new Student();
    		student.setId(Integer.parseInt(id));
    		student.setScore(score);
    		this.generaService.updatescore(student);
    		ModelAndView mav = new ModelAndView("teacher/addscore");
    		return mav;
    	}
    }
    

    四、其他

    1.其他系统实现

    1.JavaWeb系统系列实现

    Java+JSP实现学生图书管理系统

    Java+JSP实现学生信息管理系统

    Java+JSP实现用户信息管理系统

    Java+Servlet+JSP实现航空订票系统

    Java+Servlet+JSP实现新闻发布系统

    Java+Servlet+JSP实现图书管理系统

    Java+Servlet+JSP实现停车场管理系统

    Java+Servlet+JSP实现学生信息管理系统

    Java+Servlet+JSP实现学生选课管理系统

    Java+Servlet+JSP实现学生成绩管理系统-1

    Java+Servlet+JSP实现学生成绩管理系统-2

    Java+Servlet+JSP实现宠物诊所管理系统

    Java+SSM+JSP实现网上考试系统

    Java+SSH+JSP实现在线考试系统

    Java+SSH+JSP实现医院在线挂号系统

    Java+Springboot+Mybatis+Bootstrap+Maven实现网上商城系统

    2.JavaSwing系统系列实现

    Java+Swing实现斗地主游戏

    Java+Swing实现图书管理系统

    Java+Swing实现医院管理系统

    Java+Swing实现考试管理系统

    Java+Swing实现仓库管理系统-1

    Java+Swing实现仓库管理系统-2

    Java+Swing实现自助取款机系统

    Java+Swing实现通讯录管理系统

    Java+Swing实现停车场管理系统

    Java+Swing实现学生信息管理系统

    Java+Swing实现学生宿舍管理系统

    Java+Swing实现学生选课管理系统

    Java+Swing实现学生成绩管理系统

    Java+Swing实现学校教材管理系统

    Java+Swing实现学校教务管理系统

    Java+Swing实现企业人事管理系统

    Java+Swing实现电子相册管理系统

    Java+Swing实现超市管理系统-TXT存储数据

    Java+Swing实现自助取款机系统-TXT存储数据

    Java+Swing实现宠物商店管理系统-TXT存储数据

    2.获取源码

    点击以下链接获取源码,数据库文件在sql文件下面。

    Java+SSM+Mysql+Layui实现学生成绩管理系统

    联系QQ:3079118617

    3.运行项目

    请点击以下链接,部署你的项目。

    IDEA如何导入JavaWeb项目超详细视频教程

    4.备注

    如有侵权请联系我删除。

    5.支持博主

    如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!想要获取其他资源可关注左侧微信公众号获取!

    展开全文
  • 教你若何创建一个自己的学生信息管理系统,可能有很多小白也在迷茫中,建议你不要灰心啊,在下面我讲给你叙述如何进行完成一套自己的系统,并且提供两套版本,一套为 IntelliJ IDEA 进行开发的版本,一套为 eclipse ...
  • 系统环境:Windows10 开发工具:Eclipse4.8.0 / MyEclipse2014 / IDEA 编码集:UTF-8 Java版本:JDK 1.8 ... 个人信息管理,课程管理,成绩管理学生信息管理等。 学生: 个人信息管理,查看自己的成绩等。
  • 这是一个数据库的课程设计作业,是基于javaweb的一个学生成绩管理系统,里面涵盖的数据库的增删改查等等操作,前端为了美观用的是bootstrap框架。
  • 运用JSP,Servlet等Web开发技术开发的一个学生成绩管理系统。1. 充分利用实验1的成果,利用JSP显示实验1的运行结果。即原来输出在控制台的结果改成用JSP显示。 2. 要求结合JSP和Servlet的特性实现相关功能。设计主页...
  • 1.3.3开发工具 IDEA 简介 2 1.3.4服务器 Tomcat 简介 2 第 2 章 系统分析 4 2.1可行性分析 4 2.1.1经济可行性分析 4 2.1.2技术可行性分析 4 2.1.3成本收益可行性分析 4 2.1.4后期开发及维护可行性分析 4 2.2需求分析...
  • 可以供新手学习,这是一个基于javaweb的成绩管理系统,说明详细。
  • IDEA+JSP+Servlet+Tomcat实现的学生成绩管理系统 学生成绩管理系统 这里写目录标题**IDEA+JSP+Servlet+Tomcat实现的学生成绩管理系统**学生成绩管理系统一、系统介绍二、系统展示三级目录 一、系统介绍 软件环境 OS...

    IDEA+JSP+Servlet+Tomcat实现的学生成绩管理系统

    学生成绩管理系统

    一、系统介绍

    软件环境
    OS:Windows10
    IDEA:2017.3.5
    Java:jdk1.8
    Mysql:8.0.13
    Bootstrap:bootstrap.min.css
    Juqery:jquery-ui-1.10.4.custom.min.css
    Tomcat:9.0.52
    Browser:Microsoft Edge

    该图书管理系统实现了学生的成绩管理。学生实现了登录登出功能,查看成绩功能。教师端实现了注册登录,对学生成绩和信息进行增删改查的功能,实现Execl导出成绩功能。
    数据库有三张表:一张是学生表(student),一张是教师表(teacher),一张是成绩表(score)。
    在这里插入图片描述
    在这里插入图片描述

    二、系统展示

    登录页面
    在这里插入图片描述
    注册页面
    在这里插入图片描述
    教师端学生成绩管理
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    学生端
    在这里插入图片描述
    在这里插入图片描述
    退出页面
    在这里插入图片描述

    三、代码实现

    1.后端实现
    Score

    package vo;
    
    public class Score {
        private String id;
        private String database;
        private String android;
        private String jsp;
    
        public String getId() {
            return id;
        }
    
        public void setId(String id) {
            this.id = id;
        }
    
        public String getDatabase() {
            return database;
        }
    
        public void setDatabase(String database) {
            this.database = database;
        }
    
        public String getAndroid() {
            return android;
        }
    
        public void setAndroid(String android) {
            this.android = android;
        }
    
        public String getJsp() {
            return jsp;
        }
    
        public void setJsp(String jsp) {
            this.jsp = jsp;
        }
    }
    
    

    Student

    package vo;
    
    public class Student {
        private String id;
        private String password;
        private String name;
        private String sex;
        private String school_date;
        private String major;
        private String email;
    
        public String getId() {
            return id;
        }
    
        public void setId(String id) {
            this.id = id;
        }
    
        public String getPassword() {
            return password;
        }
    
        public void setPassword(String password) {
            this.password = password;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getSex() {
            return sex;
        }
    
        public void setSex(String sex) {
            this.sex = sex;
        }
    
        public String getSchool_date() {
            return school_date;
        }
    
        public void setSchool_date(String school_date) {
            this.school_date = school_date;
        }
    
        public String getMajor() {
            return major;
        }
    
        public void setMajor(String major) {
            this.major = major;
        }
    
        public String getEmail() {
            return email;
        }
    
        public void setEmail(String email) {
            this.email = email;
        }
    
    }
    
    

    Teacher

    package vo;
    
    public class Teacher {
        private String id;
        private String password;
        private String email;
        private String name;
        private String sex;
    
        public String getId() {
            return id;
        }
    
        public void setId(String id) {
            this.id = id;
        }
    
        public String getPassword() {
            return password;
        }
    
        public void setPassword(String password) {
            this.password = password;
        }
    
        public String getEmail() {
            return email;
        }
    
        public void setEmail(String email) {
            this.email = email;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getSex() {
            return sex;
        }
    
        public void setSex(String sex) {
            this.sex = sex;
        }
    }
    

    ScoreDao

    package dao;
    
    import vo.Score;
    import vo.Student;
    
    import java.sql.*;
    import java.util.ArrayList;
    
    
    public class ScoreDao {
        private Connection conn = null;
        static String driver = "com.mysql.jdbc.Driver";
        static String url = "jdbc:mysql:///pby?serverTimezone=GMT%2B8";
        static String user = "root";
        static String password="root";
        /**
         * 录入成绩
         * @param id
         * @return
         * @throws Exception
         */
        /**
         * 初始化数据库连接
         *
         * @throws Exception
         */
        private void initConnection() throws Exception {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, user, password);
        }
    
        /**
         * 关闭连接
         *
         * @throws Exception
         */
        private void closeConnection() throws Exception {
            conn.close();
        }
        public boolean insertScore(String id) throws Exception{
            initConnection();
            String sql = "insert into score(id) values(?)";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, id);
            int i = ps.executeUpdate();
            closeConnection();
            return i == 1;
        }
        /**
         * 删除成绩
         * @param id
         * @return
         * @throws Exception
         */
        public boolean deleteScore(String id) throws Exception{
            initConnection();
            Statement stat = conn.createStatement();
            String sql = "delete from score where id='"+id+"'";
            int i = stat.executeUpdate(sql);
            closeConnection();
            return i==1;
        }
        /**
         * 更新成绩
         * @param id
         * @param database
         * @param android
         * @param jsp
         * @throws Exception
         */
        public void updateScoreInfo(String id, String database, String android, String jsp) throws Exception{
            initConnection();
            String sql = "update score set dat=?, android=?, jsp=? where id=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, database);
            ps.setString(2, android);
            ps.setString(3, jsp);
            ps.setString(4, id);
            ps.executeUpdate();
            closeConnection();
        }
        /**
         * 以id查找信息
         * @param id
         * @return
         * @throws Exception
         */
        public Score findWithId(String id) throws Exception{
            initConnection();
            Statement stat = conn.createStatement();
            String sql = "select * from score where id = '" + id + "'";
            ResultSet rs = stat.executeQuery(sql);
            Score stu = getScore(rs);
            closeConnection();
            return stu;
        }
        /**
         * 分页查询
         * @param page
         * @param size
         * @return
         * @throws Exception
         */
        public ArrayList<Score> getOnePage(int page, int size) throws Exception{
            ArrayList<Score> al = new ArrayList<>();
            initConnection();
            String sql = "SELECT * FROM score limit ?, ?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setInt(1, (page-1)*size);
            ps.setInt(2, size);
            ResultSet rs =  ps.executeQuery();
    //        getMoreScore(al, rs);
            closeConnection();
            return al;
        }
        /**
         * 查询总数
         * @return
         * @throws Exception
         */
        public int getScoreCount() throws Exception{
            initConnection();
            String sql = "select count(*) from score";
            Statement stat = conn.createStatement();
            ResultSet rs = stat.executeQuery(sql);
            rs.next();
            int count = rs.getInt(1);
            closeConnection();
            return count;
        }
    /**
     * 获取成绩
     * @param rs
     * @return
     * @throws SQLException
     */
    private Score getScore(ResultSet rs) throws SQLException {
        Score stu = null;
        if (rs.next()){
            stu = new Score();
            stu.setId(rs.getString("id"));
            stu.setDatabase(rs.getString("dat"));
            stu.setAndroid(rs.getString("android"));
            stu.setJsp(rs.getString("jsp"));
        }
        return stu;
    }
        /**
         * 获取所有成绩
         * @param al
         * @param rs
         * @throws SQLException
         */
        private void getMoreStudent(ArrayList<Student> al, ResultSet rs) throws SQLException {
            while (rs.next()){
                Student stu = new Student();
                stu.setId(rs.getString("id"));
                stu.setPassword(rs.getString("password"));
                stu.setName(rs.getString("name"));
                stu.setSex(rs.getString("sex"));
                stu.setSchool_date(rs.getString("school_date"));
                stu.setMajor(rs.getString("major"));
                stu.setEmail(rs.getString("email"));
                al.add(stu);
            }
        }
    
    }
    
    

    StudentDao

    package dao;
    
    import vo.Student;
    
    import java.sql.*;
    import java.util.ArrayList;
    
    public class StudentDao {
        private Connection conn = null;
        // 定义数据常量
        static String driver = "com.mysql.jdbc.Driver";
        static String url = "jdbc:mysql:///pby?serverTimezone=GMT%2B8";
        static String user = "root";
        static String password = "root";
    
        /**
         * 初始化数据库连接
         *
         * @throws Exception
         */
        private void initConnection() throws Exception {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, user, password);
        }
    
        /**
         * 关闭连接
         *
         * @throws Exception
         */
        private void closeConnection() throws Exception {
            conn.close();
        }
    
        /**
         * 验证学生账号和密码
         *
         * @param user
         * @param password
         * @return
         * @throws Exception
         */
        public Student checkAccount(String user, String password) throws Exception {
            initConnection();
            Statement stat = conn.createStatement();
            String sql = "select * from student where id = '" + user + "' and password = '" + password + "'";
            ResultSet rs = stat.executeQuery(sql);
            Student stu = getStudent(rs);
            closeConnection();
            return stu;
        }
    
        /**
         * 使用学生id来查找学生信息
         *
         * @param id
         * @return
         * @throws Exception
         */
        public Student findWithId(String id) throws Exception {
            initConnection();
            Statement stat = conn.createStatement();
            String sql = "select * from student where id = '" + id + "'";
            ResultSet rs = stat.executeQuery(sql);
            Student stu = getStudent(rs);
            closeConnection();
            return stu;
        }
        /**
         * 使用学生姓名查找学生信息
         *
         * @param name
         * @return
         * @throws Exception
         */
        public ArrayList<Student> findWithName(String name) throws Exception {
            ArrayList<Student> al = new ArrayList<>();
            initConnection();
            Statement stat = conn.createStatement();
            String sql = "select * from student where name = '" + name + "'";
            ResultSet rs = stat.executeQuery(sql);
            getMoreStudent(al, rs);
            closeConnection();
            return al;
        }
        /**
         * 添加学生信息
         *
         * @param id
         * @param name
         * @param sex
         * @param school_date
         * @param major
         * @return
         * @throws Exception
         */
        public boolean insertStudent(String id, String name, String sex, String school_date, String major) throws Exception {
            initConnection();
            String sql = "insert into student(id, name, sex, school_date, major) values(?, ?, ?, ?, ?)";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, id);
            ps.setString(2, name);
            ps.setString(3, sex);
            ps.setString(4, school_date);
            ps.setString(5, major);
            int i = ps.executeUpdate();
            closeConnection();
            return i == 1;
        }
        /**
         * 删除学生信息
         *
         * @param id
         * @return
         * @throws Exception
         */
        public boolean deleteStudent(String id) throws Exception {
            initConnection();
            Statement stat = conn.createStatement();
            String sql = "delete from student where id='" + id + "'";
            int i = stat.executeUpdate(sql);
            closeConnection();
            return i == 1;
        }
        /**
         * 获取每页的信息
         *
         * @param page
         * @param size
         * @return
         * @throws Exception
         */
        public ArrayList<Student> getOnePage(int page, int size) throws Exception {
            ArrayList<Student> al = new ArrayList<>();
            initConnection();
            String sql = "SELECT * FROM student limit ?, ?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setInt(1, (page - 1) * size);
            ps.setInt(2, size);
            ResultSet rs = ps.executeQuery();
            getMoreStudent(al, rs);
            closeConnection();
            return al;
        }
        /**
         * 获取学生总数
         *
         * @return
         * @throws Exception
         */
        public int getStudentCount() throws Exception {
            initConnection();
            String sql = "select count(*) from student";
            Statement stat = conn.createStatement();
            ResultSet rs = stat.executeQuery(sql);
            rs.next();
            int count = rs.getInt(1);
            closeConnection();
            return count;
        }
        /**
         * 更新学生信息
         *
         * @param id
         * @param name
         * @param sex
         * @param major
         * @throws Exception
         */
        public void updateStudentInfo(String id, String name, String sex, String major) throws Exception {
    
            initConnection();
            String sql = "update student set name=?, sex=?, major=? where id=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, name);
            ps.setString(2, sex);
            ps.setString(3, major);
            ps.setString(4, id);
            ps.executeUpdate();
            closeConnection();
        }
        /**
         * 更新学生密码和邮件
         *
         * @param id
         * @param email
         * @param password
         * @throws Exception
         */
        public void updateStudentSecurity(String id, String email, String password) throws Exception {
    
            initConnection();
            String sql = "update student set password=?, email=? where id=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, password);
            ps.setString(2, email);
            ps.setString(3, id);
            ps.executeUpdate();
            closeConnection();
        }
        /**
         * 获取单个学生信息
         *
         * @param rs
         * @return
         * @throws SQLException
         */
        private Student getStudent(ResultSet rs) throws SQLException {
            Student stu = null;
            if (rs.next()) {
                stu = new Student();
                stu.setId(rs.getString("id"));
                stu.setPassword(rs.getString("password"));
                stu.setName(rs.getString("name"));
                stu.setSex(rs.getString("sex"));
                stu.setSchool_date(rs.getString("school_date"));
                stu.setMajor(rs.getString("major"));
                stu.setEmail(rs.getString("email"));
            }
            return stu;
        }
        /**
         * 获取多个学生信息
         *
         * @param al
         * @param rs
         * @throws SQLException
         */
        private void getMoreStudent(ArrayList<Student> al, ResultSet rs) throws SQLException {
            while (rs.next()) {
                Student stu = new Student();
                stu.setId(rs.getString("id"));
                stu.setPassword(rs.getString("password"));
                stu.setName(rs.getString("name"));
                stu.setSex(rs.getString("sex"));
                stu.setSchool_date(rs.getString("school_date"));
                stu.setMajor(rs.getString("major"));
                stu.setEmail(rs.getString("email"));
                al.add(stu);
            }
        }
        public static void main(String[] args) throws Exception{
            StudentDao studentDao=new StudentDao();
            studentDao.initConnection();
            System.out.println("数据库连接成功");
            studentDao.closeConnection();
        }
    
    }
    

    TeacherDao

    package dao;
    
    import vo.Teacher;
    
    import java.sql.*;
    
    public class TeacherDao {
        private Connection conn = null;
        // 定义数据常量
        static String driver = "com.mysql.jdbc.Driver";
        static String url = "jdbc:mysql:///pby?serverTimezone=GMT%2B8";
        static String user = "root";
        static String password = "root";
    
        /**
         * 初始化数据库连接
         *
         * @throws Exception
         */
        private void initConnection() throws Exception {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, user, password);
        }
    
        /**
         * 关闭连接
         *
         * @throws Exception
         */
        private void closeConnection() throws Exception {
            conn.close();
        }
        public Teacher checkAccount(String id, String password) throws Exception {
            initConnection();
            Statement stat = conn.createStatement();
            String sql = "select * from teacher where id = '" + id + "' and password = '" + password + "'";
            ResultSet rs = stat.executeQuery(sql);
            Teacher tea = getTeacher(rs);
            closeConnection();
            return tea;
        }
    
        /**
         * 使用教师id来查询教师信息
         * @param id
         * @return
         * @throws Exception
         */
        public Teacher findWithId(String id) throws Exception {
            initConnection();
            Statement stat = conn.createStatement();
            String sql = "select * from teacher where id = '" + id + "'";
            ResultSet rs = stat.executeQuery(sql);
            Teacher tea = getTeacher(rs);
            closeConnection();
            return tea;
        }
    
        /**
         * 添加教师信息
         * @param id
         * @param password
         * @param email
         * @return
         * @throws Exception
         */
        public Teacher insertTeacher(String id, String password, String email) throws Exception {
            initConnection();
            String sql = "insert into teacher(id, password, email) values(?, ?, ?)";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, id);
            ps.setString(2, password);
            ps.setString(3, email);
            ps.executeUpdate();
            Teacher teacher = findWithId(id);
            closeConnection();
            return teacher;
        }
    
        /**
         * 更新教师信息
         * @param id
         * @param name
         * @param sex
         * @param email
         * @param password
         * @return
         * @throws Exception
         */
        public Teacher updateTeacher(String id, String name, String sex, String email, String password) throws Exception{
    
            initConnection();
            String sql = "update teacher set name=?, sex=?, email=?, password=? where id=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, name);
            ps.setString(2, sex);
            ps.setString(3, email);
            ps.setString(4, password);
            ps.setString(5, id);
            ps.executeUpdate();
            Teacher teacher = findWithId(id);
            closeConnection();
            return teacher;
        }
    
        /**
         * 更新教师密码
         * @param id
         * @param password
         * @throws Exception
         */
        public void updateTeacherPassword(String id, String password) throws Exception{
    
            initConnection();
            String sql = "update teacher set password=? where id=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, password);
            ps.setString(2, id);
            ps.executeUpdate();
            closeConnection();
        }
    
        /**
         * 根据ResultSet来获取教师信息
         * @param rs
         * @return
         * @throws SQLException
         */
        private Teacher getTeacher(ResultSet rs) throws SQLException {
            Teacher tea = null;
            if (rs.next()) {
                tea = new Teacher();
                tea.setId(rs.getString("id"));
                tea.setPassword(rs.getString("password"));
                tea.setName(rs.getString("name"));
                tea.setEmail(rs.getString("email"));
                tea.setSex(rs.getString("sex"));
            }
            return tea;
        }
        public static void main(String[] args) throws Exception{
            TeacherDao dao = new TeacherDao();
            dao.initConnection();
            System.out.println("数据库连接成功");
            dao.closeConnection();
        }
    }
    
    

    add_student

    package servlet;
    
    import dao.ScoreDao;
    import dao.StudentDao;
    
    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 java.io.IOException;
    import java.io.PrintWriter;
    
    @WebServlet("/add_student")
    public class add_student extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doGet(request,response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
    
            PrintWriter out = response.getWriter();
    
            StudentDao studentDao = new StudentDao();
            ScoreDao scoreDao = new ScoreDao();
    
            String id = request.getParameter("id");
            String name = request.getParameter("name");
            String sex = request.getParameter("sex");
            String major = request.getParameter("major");
            String school_date = request.getParameter("school_date");
    
            try {
                // 添加学生信息
                studentDao.insertStudent(id, name, sex, school_date, major);
                // 添加分数信息
                scoreDao.insertScore(id);
            }
            catch (Exception e){
                out.print(e);
            }
            response.sendRedirect("one_page_student");
        }
        }
    
    
    

    check_login

    package servlet;
    
    import dao.StudentDao;
    import dao.TeacherDao;
    import vo.Student;
    import vo.Teacher;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.*;
    import java.io.IOException;
    import java.io.PrintWriter;
    
    @WebServlet("/check_login")
    public class check_login extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
              this.doGet(request,response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
    
            PrintWriter out = response.getWriter();
            HttpSession session = request.getSession();
    
            // 账号
            String user = request.getParameter("user");
            // 密码
            String password = request.getParameter("password");
            // 是否记住密码
            String remember = request.getParameter("remember");
    
            // 创建Dao层
            TeacherDao teacherDao = new TeacherDao();
            StudentDao studentDao = new StudentDao();
    
            // 创建实体类
            Teacher teacher = null;
            Student student = null;
    
            try {
                // 判断用户身份
                teacher = teacherDao.checkAccount(user, password);
                student = studentDao.checkAccount(user, password);
            }
            catch (Exception e) {
                out.print(e);
            }
    
            if (teacher != null) {
                //向session中添加用户信息
                session.setAttribute("info", teacher);
    
                //检查用户是否需要保持登录状态
                if (remember != null) {
                    //发送cookie到客户端
                    Cookie userCookie = new Cookie("name", user);
                    userCookie.setMaxAge(10);
                    response.addCookie(userCookie);
                }
                // 重定向
                response.sendRedirect("one_page_student");
            }
            else if (student != null){
                //向session中添加用户信息
                session.setAttribute("info", student);
    
                //检查用户是否需要保持登录状态
                if (remember != null) {
                    //发送cookie到客户端
                    Cookie userCookie = new Cookie("name", user);
                    userCookie.setMaxAge(10);
                    response.addCookie(userCookie);
                }
                response.sendRedirect("student/main.jsp");
            }
            else {
                out.print("<script>alert(\"用户名或密码错误!\");");
            }
    
        }
    }
    
    

    check_register

    package servlet;
    
    import dao.TeacherDao;
    import vo.Teacher;
    
    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 javax.servlet.http.HttpSession;
    import java.io.IOException;
    import java.io.PrintWriter;
    
    @WebServlet("/check_register")
    public class check_register extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
    
            String email = request.getParameter("email");
            String user = request.getParameter("user");
            String password = request.getParameter("password1");
            String code = request.getParameter("code");
    
            PrintWriter out = response.getWriter();
            HttpSession session = request.getSession();
    
            String randStr = (String) session.getAttribute("randStr");
    
            if (!code.equals(randStr)) {
                out.print("<script>alert(\"验证码错误!\");location.href = \"register.jsp\";</script>");
            } else {
    
                TeacherDao teacherDao = new TeacherDao();
                Teacher teacher = null;
    
                try {
                    teacher = teacherDao.insertTeacher(user, password, email);
                } catch (Exception e) {
                    out.print(e);
                }
                if (teacher != null) {
                    //向session中添加用户信息
                    session.setAttribute("info", teacher);
                    response.sendRedirect("one_page_student");
                } else {
                    out.print("<script>alert(\"此用户已经注册!\");location.href = \"register.jsp\";</script>");
                }
            }
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    this.doPost(request,response);
        }
    
    
    
    }
    
    

    delete_student

    package servlet;
    
    import dao.ScoreDao;
    import dao.StudentDao;
    
    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 java.io.IOException;
    import java.io.PrintWriter;
    
    @WebServlet("/delete_student")
    public class delete_student extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    this.doGet(request, response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
    
            PrintWriter out = response.getWriter();
            StudentDao studentDao = new StudentDao();
            ScoreDao scoreDao = new ScoreDao();
    
            String id = request.getParameter("id");
            try {
                // 删除学生
                studentDao.deleteStudent(id);
                // 删除成绩
                scoreDao.deleteScore(id);
                response.sendRedirect("one_page_student");
            }
            catch (Exception e){
                out.print(e);
            }
        }
    
    }
    
    

    exit

    package servlet;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.Cookie;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.IOException;
    
    @WebServlet("/exit")
    public class exit extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    this.doGet(request, response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //清除cookie, 跳到起始页
            Cookie[] cookies = request.getCookies();
            if (cookies != null) {
                for (Cookie c : cookies) {
                    String cookieName = c.getName();
                    if ("name".equals(cookieName)) {
                        c.setMaxAge(0);
                        response.addCookie(c);
                    }
                }
            }
            response.sendRedirect("index.jsp");
        }
        }
    

    one_page_score

    package servlet;
    
    import dao.ScoreDao;
    import vo.Score;
    
    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 javax.servlet.http.HttpSession;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.ArrayList;
    
    @WebServlet("/one_page_score")
    public class one_page_score extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    this.doGet(request, response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
    
            PrintWriter out = response.getWriter();
            HttpSession session = request.getSession();
    
            // 获取传入id的值
            String key = request.getParameter("id");
    
            if (key == null) {
    
                int currentIndex, count, size = 10;
                String index = request.getParameter("index");
                if (index == null)
                    index = "1";
                currentIndex = Integer.parseInt(index);
    
                try {
                    ScoreDao scoD = new ScoreDao();
                    count = scoD.getScoreCount();
                    ArrayList<Score> stus = scoD.getOnePage(currentIndex, size);
                    int sumIndex = count % size == 0 ? count / size : count / size + 1;
                    session.setAttribute("onePageScore", stus);
                    session.setAttribute("sumScoreIndex", sumIndex);
                    response.sendRedirect("teacher/score.jsp");
                } catch (Exception e) {
                    out.print(e);
                }
            }
            else {
                ScoreDao scoreDao = new ScoreDao();
                try {
                    Score score = scoreDao.findWithId(key);
                    ArrayList<Score> scores = new ArrayList<>();
                    scores.add(score);
                    session.setAttribute("onePageScore", scores);
                    session.setAttribute("sumScoreIndex", 1);
                    response.sendRedirect("teacher/score.jsp");
                } catch (Exception e) {
                    out.print(e);
                }
            }
        }
    
    }
    

    one_page_student

    package servlet;
    
    import dao.StudentDao;
    import vo.Student;
    
    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 javax.servlet.http.HttpSession;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.ArrayList;
    import java.util.regex.Pattern;
    
    @WebServlet("/one_page_student ")
    public class one_page_student extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doGet(request, response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
    
            PrintWriter out = response.getWriter();
            HttpSession session = request.getSession();
    
            // 获取key的值
            String key = request.getParameter("key");
    
            // 如果key为空或者空字符串
            if (key == null || key.equals("")) {
                int currentIndex, count, size = 10;
                String index = request.getParameter("index");
                if (index == null)
                    index = "1";
                // 当前页赋值
                currentIndex = Integer.parseInt(index);
    
                try {
                    StudentDao sdao = new StudentDao();
                    // 查询当前页信息
                    ArrayList<Student> stus = sdao.getOnePage(currentIndex, size);
                    count = sdao.getStudentCount();
                    // 计算总页数
                    int sumIndex = count % size == 0 ? count / size : count / size + 1;
                    session.setAttribute("onePageStudent", stus);
                    session.setAttribute("sumIndex", sumIndex);
                    response.sendRedirect("teacher/main.jsp");
                } catch (Exception e) {
                    out.print(e);
                }
            }
            else {
    
                StudentDao studentDao = new StudentDao();
                // 这里前一个"\"是转义字符,后一个是字符串,这个字符串表示数字至少出现一次
                String pattern = "^\\d+";
                boolean isMatch = Pattern.matches(pattern, key);
                if (isMatch) {
                    try {
    
                        // 某个学生的信息
                        Student student = studentDao.findWithId(key);
                        ArrayList<Student> students = new ArrayList<>();
                        students.add(student);
                        session.setAttribute("onePageStudent", students);
                        session.setAttribute("sumIndex", 1);
                        response.sendRedirect("teacher/main.jsp");
                    } catch (Exception e) {
                        out.print(e);
                    }
                } else {
                    try {
                        ArrayList<Student> stus = studentDao.findWithName(key);
                        session.setAttribute("onePageStudent", stus);
                        session.setAttribute("sumIndex", 1);
                        response.sendRedirect("teacher/main.jsp");
                    } catch (Exception e) {
                        out.print(e);
                    }
                }
            }
        }
    
        }
    
    
    

    update_student

    package servlet;
    
    import dao.StudentDao;
    
    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 java.io.IOException;
    import java.io.PrintWriter;
    
    @WebServlet("/update_student")
    public class update_student extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    this.doGet(request, response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
    
            PrintWriter out = response.getWriter();
            StudentDao studentDao = new StudentDao();
    
            String stuno = request.getParameter("stuno");
            String stuname = request.getParameter("stuname");
            String stusex = request.getParameter("stusex");
            String stumajor = request.getParameter("stumajor");
    
            try {
                // 更新学生信息
                studentDao.updateStudentInfo(stuno, stuname, stusex, stumajor);
            }
            catch (Exception e){
                out.print(e);
            }
            response.sendRedirect("one_page_student");
        }
        }
    
    

    update_teacher

    package servlet;
    
    import dao.TeacherDao;
    import vo.Teacher;
    
    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 javax.servlet.http.HttpSession;
    import java.io.IOException;
    import java.io.PrintWriter;
    
    @WebServlet("/update_teacher")
    public class update_teacher extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
    
            PrintWriter out = response.getWriter();
            HttpSession session = request.getSession();
    
            TeacherDao teacherDao = new TeacherDao();
    
            String uid = request.getParameter("uid");
            String name = request.getParameter("name");
            String sex = request.getParameter("sex");
            String email = request.getParameter("email");
            String password = request.getParameter("password");
            try {
                // 更新教师信息
                Teacher teacher = teacherDao.updateTeacher(uid, name, sex, email, password);
                session.setAttribute("info", teacher);
                out.print("<script>alert(\"保存成功!\");location.href = \"teacher/personal.jsp\";</script>");
            }
            catch (Exception e){
                out.print(e);
            }
    
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doPost(request, response);
        }
    }
    
    

    upload_studentImg

    package servlet;//import org.omg.CORBA.Request;
    
    import com.jspsmart.upload.SmartUpload;
    
    import javax.servlet.ServletConfig;
    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 java.io.IOException;
    import java.io.PrintWriter;
    
    @WebServlet("/upload_studentImg")
    public class upload_studentImg extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    this.doGet(request, response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
            PrintWriter out = response.getWriter();
    
            SmartUpload smartUpload = new SmartUpload();
            com.jspsmart.upload.Request rq = smartUpload.getRequest();
            ServletConfig config = this.getServletConfig();
            smartUpload.initialize(config, request, response);
            try {
                //上传文件
                smartUpload.upload();
                String id = rq.getParameter("id");
                com.jspsmart.upload.File smartFile = smartUpload.getFiles().getFile(0);
                smartFile.saveAs("/userImg/"+id+".jpeg");
                out.print("<script>alert(\"上传成功!\");window.location.href='student/personal.jsp';</script>");
            }
            catch (Exception e){
                out.print(e);
            }
        }
    
    }
    
    

    upload_teacherImg

    package servlet;
    
    import com.jspsmart.upload.File;
    import com.jspsmart.upload.Request;
    import com.jspsmart.upload.SmartUpload;
    
    import javax.servlet.ServletConfig;
    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 java.io.IOException;
    import java.io.PrintWriter;
    
    @WebServlet("/upload_teacherImg")
    public class upload_teacherImg extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    this.doGet(request, response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
            PrintWriter out = response.getWriter();
    
            SmartUpload smartUpload = new SmartUpload();
            Request rq = smartUpload.getRequest();
            ServletConfig config = this.getServletConfig();
            smartUpload.initialize(config, request, response);
            try {
                //上传文件
                smartUpload.upload();
                String id = rq.getParameter("id");
                File smartFile = smartUpload.getFiles().getFile(0);
                smartFile.saveAs("/userImg/"+id+".jpeg");
                out.print("<script>alert(\"上传成功!\");window.location.href='teacher/personal.jsp';</script>");
            }
            catch (Exception e){
                out.print(e);
            }
        }
    
    }
    
    

    2.前端实现
    student(main.jsp)

    <%@ page import="dao.StudentDao" %>
    <%@ page import="dao.ScoreDao" %>
    <%@ page import="vo.Score" %>
    <%@ page import="vo.Student" %>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>main</title>
        <link href="../resources/css/default.css" rel="stylesheet"/>
    </head>
    <body style="background:#c3e6cb">
    <%
        Student student = (Student) session.getAttribute("info");
    %>
    <div id="page" class="container">
        <div id="header">
            <div id="logo">
                <img src="../userImg/<%=student.getId()%>.jpeg"/>
                <h1><%=student.getName()%></h1>
            </div>
            <div id="menu">
                <ul>
                    <li><a href="personal.jsp">个人信息</a></li>
                    <li class="current_page_item"><a href="main.jsp">我的成绩</a></li>
                    <li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li>
                </ul>
            </div>
        </div>
        <div id="main">
            <div class="top">
                <h2 style="color: darkslateblue">我的成绩</h2>
                <hr/>
            </div>
            <div class="table">
                <table width="800" frame="box" align="center">
                    <tr>
                        <th height="35">学号/工号</th>
                        <th>姓名</th>
                        <th>学院</th>
                        <th>数据库</th>
                        <th>安卓</th>
                        <th>JSP</th>
                        <%--<th>操作</th>--%>
                    </tr>
                    <%
                        try {
                            ScoreDao scoD = new ScoreDao();
                            StudentDao stuD = new StudentDao();
                            Score stu = scoD.findWithId(student.getId());
                            String name = stuD.findWithId(student.getId()).getName();
                            String major = stuD.findWithId(student.getId()).getMajor();
                    %>
                    <tr>
                        <td height="35"><%=stu.getId()%></td>
                        <td><%=name%></td>
                        <td><%=major%></td>
                        <td><%=stu.getDatabase()%></td>
                        <td><%=stu.getAndroid()%></td>
                        <td><%=stu.getJsp()%></td>
                        <%--<td><a href="pdf.jsp?id=<%=stu.getId()%>&name=<%=name%>&major=<%=major%>&database=<%=stu.getDatabase()%>&android=<%=stu.getAndroid()%>&jsp=<%=stu.getJsp()%>">PDF</a></td>--%>
                    </tr>
                    <%
                        }
                        catch (Exception e){
                            out.print(e);
                        }
                    %>
                </table>
            </div>
        </div>
    </div>
    </body>
    </html>
    
    </body>
    </html>
    
    

    student(person.jsp)

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>main</title>
        link rel="stylesheet" href="../resources/css/jquery-ui-1.10.4.custom.min.css">
        <script src="../resources/js/jquery-1.10.2.js"></script>
        <script src="../resources/js/jquery-ui-1.10.4.custom.min.js"></script>
        <link href="../resources/css/default.css" rel="stylesheet"/>
    </head>
    <body style="background: #c3e6cb">
    <%
        Student student = (Student) session.getAttribute("info");
    %>
    <div id="page" class="container">
        <div id="header">
            <div id="logo">
                <img src="../userImg/<%=student.getId()%>.jpeg"/>
                <h1><%=student.getName()%></h1>
            </div>
            <div id="menu">
                <ul>
                    <li class="current_page_item"><a href="personal.jsp" style="color: #10707f">个人信息</a></li>
                    <li><a href="main.jsp" style="color: #10707f">我的成绩</a></li>
                    <li><a onclick="return confirm('确认退出?');" href="../exit" style="color: #10707f">退出登录</a></li>
                </ul>
            </div>
        </div>
        <div id="main">
            <div class="top">
                <h2 style="color: darkslateblue">我的成绩</h2>
                <hr/>
            </div>
            <div class="info">
                <img src="../userImg/<%=student.getId()%>.jpeg" class="personalImg"><br>
                <form action="../upload_studentImg" method="post" enctype="multipart/form-data">
                    <input type="hidden" name="id" value="<%=student.getId()%>">
                    <input type="file" name="img">
                    <input type="submit" value="上传头像">
                </form>
    
                <form action="../update_student_email" method="post">
                    <table width="400" frame="box" align="center" style="margin-top: 30px;">
                        <tr>
                            <td style="font-size: 25px;font-weight: bold">学号</td>
                            <td style="font-size: 25px;font-weight: bold"><%=student.getId()%></td>
                        </tr>
                        <tr>
                            <td style="font-size: 25px;font-weight: bold">姓名</td>
                            <td style="font-size: 25px;font-weight: bold"><%=student.getName()%></td>
                        </tr>
                        <tr>
                            <td style="font-size: 25px;font-weight: bold">性别</td>
                            <td style="font-size: 25px;font-weight: bold"><%=student.getSex()%></td>
                        </tr>
                        <tr>
                            <td style="font-size: 25px;font-weight: bold">学院</td>
                            <td style="font-size: 25px;font-weight: bold"><%=student.getMajor()%></td>
                        </tr>
                    </table>
                </form>
                <button class="password-btn" style="margin-top: 30px; height: 40px">修改安全信息</button>
            </div>
        </div>
    </div>
    
    <%--修改密码对话框--%>
    <div id="password-dialog" title="修改安全信息" style="color: #004085">
        <form id="password-form" method="post">
            <input type="hidden" name="id" value="<%=student.getId()%>">
            <%--邮箱: &nbsp;&nbsp;<input type="email" name="email" value="<%=student.getEmail()%>"><br><br>--%>
            新密码:<input type="password" name="password"><br>
            <hr>
            <input style="float: right " type="submit" value="取消" onclick="function x() {
              $('#add-dialog').dialog('close');
            }">
            <input style="float: right; margin-right: 25px" type="submit" value="保存"
                   onclick="this.form.action='../update_student_security'">
        </form>
    </div>
    
    <script>
        $('#password-dialog').dialog({
            width: 340,
            autoOpen: false,
            draggable: false,
            modal: true,
            resizable: false
        });
        $('.password-btn').click(function () {
            $('#password-dialog').dialog('open');
        });
    </script>
    
    <style>
        .ui-dialog-titlebar-close {
            display: none
        }
    </style>
    </body>
    </html>
    

    student(resetPassword.jsp)

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>重置密码</title>
        <link rel="stylesheet" href="../resources/css/bootstrap.min.css">
        <link href="../resources/css/forget.css" type="text/css" rel="stylesheet" />
    </head>
    <body style="background: #c3e6cb">
    h1 style="margin: 0px 80px; color:darkslateblue; font-family: STCaiyun">学生成绩管理系统</h1><br>
    
    <%
        String id = request.getParameter("id");
        String email = request.getParameter("email");
        String reset = request.getParameter("reset");
        String code = (String) session.getAttribute("reset");
        if (!reset.equals(code)){
    %>
    <script>alert("验证码错误!");window.location.href='../forget.jsp';</script>
    <%
    }
    else {
    %>
    <div class="main">
        <form role="form" action="../update_student_security" method="post">
            <div class="form-group" align="center">
                <input class="form-control" type="text" name="password" placeholder="新密码"><br>
                <input type="hidden" name="id" value="<%=id%>">
                <input type="hidden" name="email" value="<%=email%>">
                <input type="submit" class="btn btn-success" value="提交">
                <input type="button" class="btn btn-info" value="取消" style="margin-left: 20px" onclick="window.location.href='../login.jsp'">
            </div>
        </form>
    </div>
    <%
        }
    %>
    <script src="../resources/js/jquery-3.2.1.min.js"></script>
    <script src="../resources/js/popper.min.js"></script>
    <script src="../resources/js/bootstrap.min.js"></script>
    </body>
    </html>
    
    

    teacher(main.jsp)

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ page import="vo.Student" %>
    <%@ page import="vo.Teacher" %>
    <%@ page import="java.util.ArrayList" %>
    <html>
    <head>
        <link rel="stylesheet" href="../resources/css/jquery-ui-1.10.4.custom.min.css">
        <script src="../resources/js/jquery-1.10.2.js"></script>
        <script src="../resources/js/jquery-ui-1.10.4.custom.min.js"></script>
        <title>main</title>
        <link href="../resources/css/default.css" rel="stylesheet"/>
    </head>
    <body style="background: #c3e6cb">
    <%
        Teacher teacher = (Teacher) session.getAttribute("info");
        ArrayList<Student> stus = (ArrayList<Student>) session.getAttribute("onePageStudent");
        int sumIndex = (int) session.getAttribute("sumIndex");
    %>
    
    
    <div id="page" class="container">
        <div id="header">
    
            logo部分
            <div id="logo">
                <img src="../userImg/<%=teacher.getId()%>.jpeg"/>
                <h1><%=teacher.getId()%>
                </h1>
            </div>
    
    
            <%-- 左面的功能栏 --%>
            <div id="menu">
                <ul>
                    <li><a href="personal.jsp">个人信息</a></li>
                    <li class="current_page_item"><a href="../one_page_student">学生信息管理</a></li>
                    <li><a href="../one_page_score">学生成绩管理</a></li>
                    <li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li>
                </ul>
            </div>
    
        </div>
        <div id="main">
            <div class="top">
                <h2 style="color: darkslateblue">学生成绩管理</h2>
                <hr/>
                <button class="btn-add" style="color: #2980b9">添加学生信息</button>
                <div class="find">
                    <form action="../one_page_student" method="post">
                        <input id="find-text" type="text" name="key" placeholder="输入学号/工号或姓名搜索">
                        <input class="find-btn" type="submit" value="搜索">
                    </form>
                </div>
            </div>
            <div class="table">
                <table id="table" width="800" frame="box" align="center">
                    <tr>
                        <th height="35">学号/工号</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>班级</th>
                        <th>学院</th>
                        <th>操作</th>
                    </tr>
                    <%
                        for (Student stu : stus) {
                    %>
                    <tr>
                        <form method="post" action="../update_student">
                            <td height="35"><%=stu.getId()%></td>
                            <td><input value="<%=stu.getName()%>" name="stuname" class="table-input"></td>
                            <td><input value="<%=stu.getSex()%>" name="stusex" class="table-input"></td>
                            <td><%=stu.getSchool_date()%></td>
                            <td><input value="<%=stu.getMajor()%>" name="stumajor" class="table-input" style="width: 110px"></td>
                            <input value="<%=stu.getId()%>" name="stuno" type="hidden">
                            <td><input type="submit" class="update-btn" value="修改">&nbsp;
                                <a class="btn-delete" onclick="return confirm('确定要删除吗?');"
                                   href=<%="'../delete_student?id=" + stu.getId() + "'"%>>删除</a>&nbsp;&nbsp;
                                <a href="../one_page_score?id=<%=stu.getId()%>" style="color: #117a8b">学生成绩</a>
                            </td>
                        </form>
                    </tr>
                    <%
                        }
                    %>
                </table>
            </div>
            <%
                if (sumIndex > 1){
            %>
            <div id="index">
                <a href="../one_page_student?index=1">首页</a>
                <%
                    for (int i=1; i<=sumIndex; i++){
                %>
                <a href="../one_page_student?index=<%=i%>"><%=i%></a>
                <%
                    }
                %>
                <a href="../one_page_student?index=<%=sumIndex%>">尾页</a>
            </div>
            <%
                }
            %>
        </div>
    </div>
    
    <%--添加学生信息对话框--%>
    <div id="add-dialog" title="添加学生信息">
        <form id="add-form" method="post">
            学号:<input name="id" type="text"><br>
            姓名:<input name="name" type="text"><br>
            性别:<input name="sex" type="text"><br>
            班级:<input name="school_date" type="text">
            学院:<input name="major" type="text"><br>
    
            <hr>
            <input style="float: right" type="submit" value="取消" onclick="function x() {
              $('#add-dialog').dialog('close');
            }">
            <input style="float: right; margin-right: 25px" type="submit" value="确定"
                   onclick="this.form.action='../add_student'">
        </form>
    </div>
    
    <style>
        .ui-dialog-titlebar-close {
            display: none
        }
    </style>
    
    <script>
        $('#add-dialog').dialog({
            width: 310,
            autoOpen: false,
            draggable: false,
            modal: true,
            resizable: false
        });
        $('.btn-add').click(function () {
            $('#add-dialog').dialog('open');
        });
    </script>
    </body>
    </html>
    

    teacher(personal.jsp)

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>main</title>
        <link href="../resources/css/default.css" rel="stylesheet"/>
    </head>
    <body style="background: #c3e6cb">
    <%
        Teacher teacher = (Teacher) session.getAttribute("info");
    %>
    <div id="page" class="container">
        <div id="header">
            <div id="logo">
                <img src="../userImg/<%=teacher.getId()%>.jpeg"/>
                <h1><%=teacher.getId()%>
                </h1>
            </div>
            <div id="menu">
                <ul>
                    <li class="current_page_item"><a href="personal.jsp">个人信息</a></li>
                    <li><a href="../one_page_student">学生信息管理</a></li>
                    <li><a href="../one_page_score">学生成绩管理</a></li>
                    <li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li>
                </ul>
            </div>
        </div>
        <div id="main">
            <div class="top">
                <h2 style="color: darkslateblue">个人信息</h2>
                <hr/>
            </div>
            <div class="info">
                <img src="../userImg/<%=teacher.getId()%>.jpeg" class="personalImg"><br>
                <form action="../upload_teacherImg" method="post" enctype="multipart/form-data">
                    <input type="hidden" name="id" value="<%=teacher.getId()%>">
                    <input type="file" name="img">
                    <input type="submit" value="上传头像">
                </form>
                <form method="post" action="../update_teacher" class="personalForm">
                    <input name="uid" value="<%=teacher.getId()%>" type="hidden">
                    姓名: <input type="text" name="name" value="<%=teacher.getName()%>" class="personalInput"><br>
                    性别: <input type="text" name="sex" value="<%=teacher.getSex()%>" class="personalInput"><br>
                    邮箱: <input type="text" name="email" value="<%=teacher.getEmail()%>" class="personalInput"><br>
                    密码: <input type="text" name="password" value="<%=teacher.getPassword()%>" class="personalInput"><br>
                    <input type="submit" value="保存" style="width: 100px; height: 30px; margin-top: 20px">
                </form>
            </div>
        </div>
    </div>
    </body>
    </html>
    
    

    teacher(resetPassword.jsp)

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>重置密码</title>
        <link rel="stylesheet" href="../resources/css/bootstrap.min.css">
        <link href="../resources/css/forget.css" type="text/css" rel="stylesheet" />
    </head>
    <body>
    <h1 style="margin: 0px 80px; color:darkslateblue; font-family: STCaiyun">学生成绩管理系统</h1><br>
    
    
    <%
        String id = request.getParameter("id");
        String reset = request.getParameter("reset");
        String code = (String) session.getAttribute("reset");
        if (!reset.equals(code)){
    %>
    <script>alert("验证码错误!");window.location.href='../forget.jsp';</script>
    <%
    } else {
    %>
    <div class="main">
        <form role="form" action="../update_teacher_password" method="post">
            <div class="form-group" align="center">
                <input type="text" class="form-control" name="password" placeholder="新密码"><br>
                <input type="hidden" name="id" value="<%=id%>">
                <input type="submit" class="btn btn-success" value="提交">
                <input type="button" class="btn btn-info" value="取消" style="margin-left: 20px" onclick="window.location.href='../login.jsp'">
            </div>
        </form>
    </div>
    <%
        }
    %>
    <script src="../resources/js/jquery-3.2.1.min.js"></script>
    <script src="../resources/js/popper.min.js"></script>
    <script src="../resources/js/bootstrap.min.js"></script>
    </body>
    </html>
    
    

    teacher(score.jsp)

    <%@ page import="dao.StudentDao" %>
    <%@ page import="vo.Score" %>
    <%@ page import="vo.Teacher" %>
    <%@ page import="java.util.ArrayList" %><%--
      Created by IntelliJ IDEA.
      User: 12276
      Date: 2021/10/23
      Time: 12:26
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>main</title>
        <link href="../resources/css/default.css" rel="stylesheet"/>
    </head>
    <body style="background: #c3e6cb">
    <%
        Teacher teacher = (Teacher) session.getAttribute("info");
        ArrayList<Score> stus = (ArrayList<Score>) session.getAttribute("onePageScore");
        int sumIndex = (int) session.getAttribute("sumScoreIndex");
    %>
    <div id="page" class="container">
        <div id="header">
            <div id="logo">
                <img src="../userImg/<%=teacher.getId()%>.jpeg"/>
                <h1><%=teacher.getId()%>
                </h1>
            </div>
            <div id="menu">
                <ul>
                    <li><a href="personal.jsp">个人信息</a></li>
                    <li><a href="../one_page_student">学生信息管理</a></li>
                    <li class="current_page_item"><a href="../one_page_score">学生成绩管理</a></li>
                    <li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li>
                </ul>
            </div>
        </div>
        <div id="main">
            <div class="top">
                <h2 style="color: darkslateblue">学生成绩管理</h2>
                <hr/>
            </div>
            <form method="post" action="../update_score" style="height: 525px; margin-top: 20px">
                <input type="button" class="btn-add" onclick="location.href='score_excel.jsp';" value="导出EXCEL">
                <input type="submit" class="btn-add" style="float: right;margin-bottom: 30px" value="修改">
                <div class="table" style="margin-top: 20px; height: 525px">
                    <table id="table" width="800" frame="box" align="center">
                        <tr>
                            <th height="35">学号</th>
                            <th>姓名</th>
                            <th>学院</th>
                            <th>数据库</th>
                            <th>安卓</th>
                            <th>JSP</th>
                        </tr>
                        <%
                            try {
                                StudentDao stuD = new StudentDao();
                                for (Score stu : stus) {
                                    String name = stuD.findWithId(stu.getId()).getName();
                                    String major = stuD.findWithId(stu.getId()).getMajor();
                        %>
                        <tr>
                            <td height="35"><%=stu.getId()%></td>
                            <td><%=name%></td>
                            <td><%=major%></td>
                            <td><input value="<%=stu.getDatabase()%>" name="database" class="table-input"></td>
                            <td><input value="<%=stu.getAndroid()%>" name="android" class="table-input"></td>
                            <td><input value="<%=stu.getJsp()%>" name="jsp" class="table-input"></td>
                            <input value="<%=stu.getId()%>" name="id" type="hidden">
                        </tr>
                        <%
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        %>
                    </table>
    
                </div>
            </form>
            <%-- 展示下面的页签数 --%>
            <%
                if (sumIndex > 1){
            %>
            <div id="index">
                <a href="../one_page_score?index=1">首页</a>
                <%
                    for (int i = 1; i <= sumIndex; i++) {
                %>
                <a href="../one_page_score?index=<%=i%>"><%=i%></a>
                <%
                    }
                %>
                <a href="../one_page_score?index=<%=sumIndex%>">尾页</a>
            </div>
            <%
                }
            %>
        </div>
    </div>
    </body>
    </html>
    

    teacher(score_excel.jsp)

    <%@ page import="dao.ScoreDao" %>
    <%@ page import="dao.StudentDao" %>
    <%@ page import="vo.Score" %>
    <%@ page import="java.util.ArrayList" %><%--
      Created by IntelliJ IDEA.
      User: 12276
      Date: 2021/10/23
      Time: 12:30
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>main</title>
    </head>
    <body style="background: #c3e6cb">
    <%
        out.clearBuffer();
        response.setHeader("Content-Disposition", "attachment;filename=excel.xls");
    %>
    <table align="center" border="1">
        <tr>
            <th height="35">学号</th>
            <th>姓名</th>
            <th>学院</th>
            <th>数据库</th>
            <th>安卓</th>
            <th>JSP</th>
        </tr>
        <%
            try {
                ScoreDao scoD = new ScoreDao();
                StudentDao stuD = new StudentDao();
                ArrayList<Score> stus = scoD.getOnePage(1, 10000);
                for (Score stu : stus) {
                    String name = stuD.findWithId(stu.getId()).getName();
                    String major = stuD.findWithId(stu.getId()).getMajor();
        %>
        <tr>
            <td align="center"><%=stu.getId()%></td>
            <td align="center"><%=name%></td>
            <td align="center"><%=major%></td>
            <td align="center"><%=stu.getDatabase()%></td>
            <td align="center"><%=stu.getAndroid()%></td>
            <td align="center"><%=stu.getJsp()%></td>
        </tr>
        <%
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        %>
    </table>
    </body>
    </html>
    
    

    code.jsp

    <%@ page import="java.awt.image.BufferedImage" %>
    <%@ page import="java.awt.*" %>
    <%@ page import="java.util.Random" %>
    <%@ page import="javax.imageio.ImageIO" %><%--
      Created by IntelliJ IDEA.
      User: 12276
      Date: 2021/10/23
      Time: 12:32
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
    </head>
    <body>
    <%
        response.setCharacterEncoding("utf-8");
    
        response.setHeader("Cache-Control", "no-cache");
        //创建图像
        int width = 60, height = 20;
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        //获取画笔
        Graphics g = image.getGraphics();
        //设定背景色
        g.setColor(new Color(100, 200, 200));
        g.fillRect(0, 0, width, height);
        //随机产生四位数字
        Random rnd = new Random();
        int randNum = rnd.nextInt(8999) + 1000;
        String randStr = String.valueOf(randNum);
        //将验证码存入session
        session.setAttribute("randStr", randStr);
        //显示到图像中
        g.setColor(Color.BLACK);
        g.setFont(new Font("", Font.PLAIN, 20));
        g.drawString(randStr, 10, 17);
        //随机产生100个干扰点
        for (int i = 0; i < 100; i++) {
            int x = rnd.nextInt(width);
            int y = rnd.nextInt(height);
            g.drawOval(x, y, 1, 1);
        }
        //输出到页面
        ImageIO.write(image, "jpeg", response.getOutputStream());
        out.clear();
        out = pageContext.pushBody();
    %>
    </body>
    </html>
    
    

    login.jsp

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>请登陆</title>
        <link rel="stylesheet" href="resources/js/bootstrap.min.css">
        <link href="resources/css/login.css" type="text/css" rel="stylesheet" />
    </head>
    <body>
    <script>
        function check(form){
            if (form.user.value === "") {
                alert("请输入账号!");
                return false;
            }
            if (form.password.value === "") {
                alert("请输入密码!");
                return false;
            }
            return true;
        }
    
    </script>
    <h1>学生成绩管理系统</h1><br>
    
    
    
    <div class="main">
        <h5 class="title">
            <a href="login.jsp" id="login">登录</a>
            <%--<b>&nbsp;·&nbsp;</b>--%>
            <a href="register.jsp" id="register">注册</a>
        </h5>
        <form action="check_login" method="post" onsubmit="return check(this)">
            <div class="form-group" >
                <b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b> <b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b>
                <input type="text" name="user" class="form-control user" placeholder="请输入用户名">
                <br>
                <b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b> <b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b>
                <input type="password" name="password" class="form-control password" placeholder="请输入密码">
                <br>
                <div class="remember-btn">
                    <input type="checkbox" name="remember" value="true">
                    <span style="color: #d4edda">记住我</span>
                </div>
                <a href="forget.jsp" class="help" style="color: #1b1e21">登录遇到问题?</a>
                <br>
                <br>
                <b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b><b>&nbsp;&nbsp;</b> <b>&nbsp;&nbsp;</b> <b>&nbsp;&nbsp;</b> <b>&nbsp;&nbsp;</b> <b>&nbsp;&nbsp;</b>
                <input type="submit" value="登录" class="btn btn-primary btn-lg btn-block" />
            </div>
        </form>
    </div>
    <script src="resources/js/jquery-3.2.1.min.js"></script>
    <script src="resources/js/popper.min.js"></script>
    <script src="resources/js/bootstrap.min.js"></script>
    </body>
    </html>
    
    

    register.jsp

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>注册</title>
        <link rel="stylesheet" href="resources/css/bootstrap.min.css">
        <link href="resources/css/register.css" type="text/css" rel="stylesheet" />
    </head>
    <body>
    <script>
        function check(form){
            if (form.user.value === "") {
                alert("请输入账号!");
                return false;
            }
            if (form.password1.value === "") {
                alert("请输入密码!");
                return false;
            }
            return true;
        }
    
        function refresh() {
            var i=Math.random();
            document.getElementById("image").src = "code.jsp?a="+i;
        }
    </script>
    <h1>学生成绩管理系统</h1><br>
    
    <div class="main">
        <h5 class="title" >
            <a href="login.jsp" id="login">登录</a>
            <b>&nbsp;·&nbsp;</b>
            <a href="register.jsp" id="register">注册</a>
        </h5>
        <form action="check_register" method="post" onsubmit="return check(this)">
            <div class="form-group">
                <input type="email" name="email" class="form-control email" placeholder="安全邮箱">
                <input type="text" name="user" class="form-control user" placeholder="用户名">
                <input type="password" name="password1" class="form-control password1" placeholder="密码">
                <input type="text" name="code" placeholder="验证码" class="code">
                <img src="code.jsp" id="image" style="float: right; width: 90px;height: 50px; margin-top: 10px" onclick="refresh()">
                <input type="submit" value="注册" class="btn btn-primary btn-lg btn-block we" />
            </div>
        </form>
    </div>
    <script src="resources/js/jquery-3.2.1.min.js"></script>
    <script src="resources/js/popper.min.js"></script>
    <script src="resources/js/bootstrap.min.js"></script>
    </body>
    </html>
    
    

    3.css

    login.css

    body{
        /*background-color: #f1f1f1;*/
    
        background:url(../img/1.jpg);
    }
    
    
    .main{
        width: 400px;
        height: 450px;
        background-color:#005cbf;
        position: absolute;
        left: 50%;
        top: 50%;
        margin: -250px 0 0 -200px;
        padding: 50px;
        border-radius:10px ;
        box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
    }
    
    .title{
        padding-top: 25px;
        padding-bottom: 40px;
        text-align: center;
    }
    
    .title a{
        padding: 10px;
        color: #b19696;
        font-weight: 500;
        text-decoration: none;
    }
    
    #login{
        font-weight: 600;
        color: #ea6f5a;
        border-bottom: 1px solid #ea6f5a;
        text-decoration: none;
    }
    
    .form-control{
        height: 50px;
    }
    
    .user{
        border-bottom: none;
        border-radius: 5px 5px 0 0;
        background:url(../img/user.png) no-repeat 5px 12px;
        background-size: 25px 25px;
        padding-left:35px;
    }
    
    .password{
        border-radius: 0 0 5px 5px;
        background:url(../img/password.png) no-repeat 8px 12px;
        background-size: 20px 20px;
        padding-left:35px;
    }
    
    .code{
        width: 200px;
        height: 30px;
        margin-top: 10px;
        border-radius: 5px;
        border: 1px solid #ced4da;
        padding-left: 10px;
    }
    
    .remember-btn{
        float: left;
        margin: 25px 0 35px;
        font-size: 14px;
        color: #999;
    }
    .form-group .help{
        float: right;
        position: relative;
        margin: 25px 0 35px;
        font-size: 14px;
        color: #999;
    }
    
    .btn{
        margin-top: 40px;
        border: none;
        border-radius: 25px;
        background: #3194d0;
    }
    
    

    forget.css

    body{
        background-color: #f1f1f1;
    }
    
    
    .main{
        width: 600px;
        height: 300px;
        position: absolute;
        left: 50%;
        top: 50%;
        margin: -150px 0 0 -300px;
        padding: 100px;
        background-color: white;
        border-radius:10px ;
        box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
    }
    

    default.css

    body
    {
    	background: #202020;
    	font-size: 12pt;
    	font-weight: 200;
    	color: #444444;
    }
    
    h1
    {
    	font-weight: 400;
    	color: #FFF;
    }
    
    ul
    {
    	padding: 0;
    	list-style: none;
    }
    
    a
    {
    	color: #2980b9;
    }
    
    a:hover
    {
    	/* 把链接取消 */
    	text-decoration: none;
    }
    
    .container
    {
    	/* 如果元素中的内容超出了给定的宽度和高度属性,overflow 属性可以确定是否显示滚动条等行为。 */
    	overflow: hidden;
    	margin: 40px auto;
    	width: 1200px;
    }
    
    /*********************************************************************************/
    /* Header                                                                        */
    /*********************************************************************************/
    
    #header
    {
    	/* 生成相对定位的元素,相对于其正常位置进行定位。 */
    	position: relative;
    	/* 向右侧浮动 */
    	float: left;
    	width: 300px;
    	/* 填充 */
    	padding: 3em 0 1em;
    }
    
    /*********************************************************************************/
    /* Logo                                                                          */
    /*********************************************************************************/
    
    #logo
    {
    	text-align: center;
    	margin-top: 1em;
    	margin-bottom: 4em;
    }
    
    #logo img
    {
    	width: 140px;
    	height: 140px;
    	display: inline-block;
    	margin-bottom: 1em;
    	border-radius: 50%;
    }
    
    #logo h1
    {
    	display: block;
    }
    
    /*********************************************************************************/
    /* Menu                                                                          */
    /*********************************************************************************/
    
    #menu li
    {
    	/* 设置上边框的样式 */
    	border-top: 1px solid rgba(255,255,255,0.08);
    }
    
    /* 没有选中的颜色及背景 */
    #menunew
    {
    	margin-top: 10em;
    	border-top: 1px solid rgba(255,255,255,0.08);
    	text-align: center;
    	text-decoration:  none;
    	text-transform: uppercase;
    	font-weight: 700;
    	color: rgba(255,255,255,0.5);
    }
    
    
    /* 没有选中的颜色及背景 */
    #menu tr a
    {
    	display: block;
    	padding: 2em 1.5em;
    	text-align: center;
    	text-decoration:  none;
    	text-transform: uppercase;
    	font-weight: 700;
    	color: rgba(255,255,255,0.5);
    }
    
    /* 当前颜色 */
    #menu .current_page_item a
    {
    	background: #2980b9;
    	color: rgba(255,255,255,1);
    }
    
    /*********************************************************************************/
    /* Page                                                                          */
    /*********************************************************************************/
    
    #page
    {
    	background: #2a2a2a;
    }
    
    /*********************************************************************************/
    /* Main                                                                          */
    /*********************************************************************************/
    
    #main
    {
    	/* 声明了显示浏览器的屏幕的高度,以像素计。 */
    	height: 675px;
    	overflow: hidden;
    	float: right;
    	width: 800px;
    	padding: 2em 50px 1em 50px;
    	background: #f9f9f9;
    	border-top: 6px solid #2980b9;
    	text-align: center;
    }
    
    .top{
    	width: 800px;
    }
    
    .table{
    	margin-top: 110px;
    	height: 433px;
    }
    
    /* 添加按钮 */
    .btn-add{
    	width: 100px;
    	height: 38px;
    	float: left;
    	margin-top: 30px;
    }
    
    /* 查找文本 */
    .find{
    	float: right;
    	margin-top: 30px;
    }
    
    /* 查找文本 */
    #find-text{
    	width: 250px;
    	height: 30px;
    }
    
    /* 查找按钮 */
    .find-btn{
    	height: 30px;
    }
    
    /* 表格输入 */
    .table-input{
    	width: 40px;
    	text-align: center;
    	border-top: none;
    	border-left: none;
    	border-right: none;
    	border-bottom-color: #e6e6e6;
    	background: transparent;
    }
    
    /* 更新按钮 */
    .update-btn{
    	font-weight: 100;
    	font-size: 16px;
    	color: #2980b9;
    	cursor:pointer;
    	border:none;
    	background:transparent;
    	text-decoration:underline
    }
    
    .update-btn:hover{
    	text-decoration: none;
    }
    
    .personalImg{
    	width: 200px;
    	height: 200px;
    	margin-bottom: 5px;
    }
    
    .info{
    	margin-top: 20px;
    }
    
    .personalForm{
    	margin-top: 20px;
    }
    
    .personalInput{
    	height: 35px;
    	margin-bottom: 10px;
    	background: transparent;
    	border-top: none;
    	border-left: none;
    	border-right: none;
    }
    
    /*
    上外边距
    */
    #index{
    	margin-top: 20px;
    }
    

    register.css

    body{
        background-color: #f1f1f1;
    }
    
    .main{
        width: 400px;
        height: 500px;
        position: absolute;
        left: 50%;
        top: 50%;
        margin: -250px 0 0 -200px;
        padding: 50px;
        background-color: white;
        border-radius:10px ;
        box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
    }
    
    .title{
        padding-top: 25px;
        padding-bottom: 40px;
        text-align: center;
    }
    
    .title a{
        padding: 10px;
        color: #b19696;
        font-weight: 500;
        text-decoration: none;
    }
    
    #register{
        font-weight: 600;
        color: #ea6f5a;
        border-bottom: 1px solid #ea6f5a;
        text-decoration: none;
    }
    
    .form-control{
        height: 50px;
    }
    
    .email{
        border-radius: 5px 5px 0 0;
        background:url(../img/email.png) no-repeat 5px 12px;
        background-size: 22px 22px;
        padding-left:35px;
    }
    
    .user{
        border-top: none;
        border-radius: 0;
        background:url(../img/user.png) no-repeat 5px 12px;
        background-size: 25px 25px;
        padding-left:35px;
    }
    
    .password1{
        border-top: none;
        border-radius: 0 0 5px 5px;
        background:url(../img/password.png) no-repeat 8px 12px;
        background-size: 20px 20px;
        padding-left:35px;
    }
    
    .code{
        width: 200px;
        height: 50px;
        margin-top: 10px;
        border-radius: 5px;
        border: 1px solid #ced4da;
        padding-left: 10px;
    }
    
    .btn{
        margin-top: 40px;
        border: none;
        border-radius: 25px;
        background: #42c02e;
    }
    
    

    所用到的jar包
    itextpdf-5.5.5.jar
    javax.annotation.jar
    javax.ejb.jar
    javax.jms.jar
    javax.persistence.jar
    javax.resource.jar
    javax.servlet.jar
    javax.servlet.jsp.jar
    javax.servlet.jsp.jstl.jar
    javax.transaction.jar
    jsmartcom_zh_CN.jar
    mysql-connector-java-5.1.46.jar

    感悟和总结

    本项目严格按照MVC模式完成,什么是MVC,以下我就来简单介绍一下:MVC模式(Model-View-Controller)是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:
    模型(Model)、视图(View)和控制器(Controller)。
    MVC模式最早为Trygve Reenskaug提出,为施乐帕罗奥多研究中心(Xerox PARC)的Smalltalk语言发明的一种软件设计模式。
    MVC可对程序的后期维护和扩展提供了方便,并且使程序某些部分的重用提供了方便。而且MVC也使程序简化,更加直观。
    * 视图View:界面设计人员进行图形界面设计;
    * 控制器Controller:对请求进行处理,负责请求转发;
    * 模型Model:程序编写程序应用的功能(实现算法等等)、数据库管理;
    * 本项目M(模型)代表着javaBean里面的的成员属性,C(控制器)代表着Servlet,V(视图)代表着jsp页面.

    注意:
        MVC不是Java的东西,几乎现在所有B/S结构的软件都采用了MVC设计模式。
    

    这个项目基本的JavaEE的知识点都包括了。但是没有用到日志框架,不过用来做简单的课程设计是绰绰有余了。

    想要源码的可以加我的QQ:2407019276,或者私信我的csdn账号。如有侵权请联系我删除。

    展开全文
  • javawweb学生成绩管理系统实验报告,首先我做的系统是学生成绩管理系统使用jsp+javabean+servlet的传统的MVC开发模式,使用mysql数据库来存储数据。其中Jsp实现视图端,Javabean是模型端,Servlet是控制端。Servlet...
  • 基于java+mysql,可生成客户端,适合学生作业!src文件为源代码,student为数据库文件,还附带数据库源代码文件
  • 学生成绩管理系统 软件环境 Operating System:Windows10 IDEA:2018.2 Java:jdk1.8 Mysql:8.0.13 Bootstrap:bootstrap.min.css Juqery:jquery-ui-1.10.4.custom.min.css Tomcat:8.5.23

    一、系统介绍

    软件环境
    OS:Windows10
    IDEA:2018.2
    Java:jdk1.8
    Mysql:8.0.13
    Bootstrap:bootstrap.min.css
    Juqery:jquery-ui-1.10.4.custom.min.css
    Tomcat:8.5.23
    Browser:Chrome

    该图书管理系统实现了学生的成绩管理。学生实现了登录登出功能,查看成绩功能。教师端实现了注册登录,对学生成绩和信息进行增删改查的功能,实现Execl导出成绩功能。
    数据库有三张表:一张是学生表(student),一张是教师表(teacher),一张是成绩表(score)。
    下面是整个工程的截图
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    二、系统展示

    1.注册页面

    在这里插入图片描述

    2.注册页面

    在这里插入图片描述

    3.教师端(学生信息管理)页面

    在这里插入图片描述

    4.教师端(添加学生信息)页面

    在这里插入图片描述

    5.教师端(学生成绩管理)页面

    在这里插入图片描述

    6.教师端(个人信息)页面

    在这里插入图片描述

    7.教师端(登出)页面

    在这里插入图片描述

    8.学生端(我的成绩)页面

    在这里插入图片描述

    9.学生端(个人信息)页面

    在这里插入图片描述

    10.学生端(登出)页面

    在这里插入图片描述

    三、代码实现

    1.前端

    student(main.jsp)

    <%@ page import="dao.StudentDao" %>
    <%@ page import="vo.Student" %>
    <%@ page import="dao.ScoreDao" %>
    <%@ page import="vo.Score" %>
    <%--
      Created by IntelliJ IDEA.
      User: 007
      Date: 2018/11/1
      Time: 20:11
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <!DOCTYPE html>
    <html>
    <head>
        <title>main</title>
        <link href="../resources/css/default.css" rel="stylesheet"/>
    </head>
    <body style="background: #c3e6cb">
    <%
        Student student = (Student) session.getAttribute("info");
    %>
    <div id="page" class="container">
        <div id="header">
            <div id="logo">
                <img src="../userImg/<%=student.getId()%>.jpeg"/>
                <h1><%=student.getName()%></h1>
            </div>
            <div id="menu">
                <ul>
                    <li><a href="personal.jsp">个人信息</a></li>
                    <li class="current_page_item"><a href="main.jsp">我的成绩</a></li>
                    <li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li>
                </ul>
            </div>
        </div>
        <div id="main">
            <div class="top">
                <h2 style="color: darkslateblue">我的成绩</h2>
                <hr/>
            </div>
            <div class="table">
                <table width="800" frame="box" align="center">
                    <tr>
                        <th height="35">学号/工号</th>
                        <th>姓名</th>
                        <th>学院</th>
                        <th>数据库</th>
                        <th>安卓</th>
                        <th>JSP</th>
                        <%--<th>操作</th>--%>
                    </tr>
                    <%
                        try {
                            ScoreDao scoD = new ScoreDao();
                            StudentDao stuD = new StudentDao();
                            Score stu = scoD.findWithId(student.getId());
                            String name = stuD.findWithId(student.getId()).getName();
                            String major = stuD.findWithId(student.getId()).getMajor();
                    %>
                    <tr>
                        <td height="35"><%=stu.getId()%></td>
                        <td><%=name%></td>
                        <td><%=major%></td>
                        <td><%=stu.getDatabase()%></td>
                        <td><%=stu.getAndroid()%></td>
                        <td><%=stu.getJsp()%></td>
                        <%--<td><a href="pdf.jsp?id=<%=stu.getId()%>&name=<%=name%>&major=<%=major%>&database=<%=stu.getDatabase()%>&android=<%=stu.getAndroid()%>&jsp=<%=stu.getJsp()%>">PDF</a></td>--%>
                    </tr>
                    <%
                        }
                        catch (Exception e){
                            out.print(e);
                        }
                    %>
                </table>
            </div>
        </div>
    </div>
    </body>
    </html>
    
    
    

    student(person.jsp)

    <%@ page import="vo.Student" %>
    <%--
      Created by IntelliJ IDEA.
      User: 007
      Date: 2018/11/1
      Time: 20:11
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <!DOCTYPE html>
    <html>
    <head>
        <title>main</title>
        <link rel="stylesheet" href="../resources/css/jquery-ui-1.10.4.custom.min.css">
        <script src="../resources/js/jquery-1.10.2.js"></script>
        <script src="../resources/js/jquery-ui-1.10.4.custom.min.js"></script>
        <link href="../resources/css/default.css" rel="stylesheet"/>
    </head>
    <body style="background: #c3e6cb">
    <%
        Student student = (Student) session.getAttribute("info");
    %>
    <div id="page" class="container">
        <div id="header">
            <div id="logo">
                <img src="../userImg/<%=student.getId()%>.jpeg"/>
                <h1><%=student.getName()%></h1>
            </div>
            <div id="menu">
                <ul>
                    <li class="current_page_item"><a href="personal.jsp" style="color: #10707f">个人信息</a></li>
                    <li><a href="main.jsp" style="color: #10707f">我的成绩</a></li>
                    <li><a onclick="return confirm('确认退出?');" href="../exit" style="color: #10707f">退出登录</a></li>
                </ul>
            </div>
        </div>
        <div id="main">
            <div class="top">
                <h2 style="color: darkslateblue">我的成绩</h2>
                <hr/>
            </div>
            <div class="info">
                <img src="../userImg/<%=student.getId()%>.jpeg" class="personalImg"><br>
                <form action="../upload_studentImg" method="post" enctype="multipart/form-data">
                    <input type="hidden" name="id" value="<%=student.getId()%>">
                    <input type="file" name="img">
                    <input type="submit" value="上传头像">
                </form>
    
                <form action="../update_student_email" method="post">
                <table width="400" frame="box" align="center" style="margin-top: 30px;">
                    <tr>
                        <td style="font-size: 25px;font-weight: bold">学号</td>
                        <td style="font-size: 25px;font-weight: bold"><%=student.getId()%></td>
                    </tr>
                    <tr>
                        <td style="font-size: 25px;font-weight: bold">姓名</td>
                        <td style="font-size: 25px;font-weight: bold"><%=student.getName()%></td>
                    </tr>
                    <tr>
                        <td style="font-size: 25px;font-weight: bold">性别</td>
                        <td style="font-size: 25px;font-weight: bold"><%=student.getSex()%></td>
                    </tr>
                    <tr>
                        <td style="font-size: 25px;font-weight: bold">学院</td>
                        <td style="font-size: 25px;font-weight: bold"><%=student.getMajor()%></td>
                    </tr>
                </table>
                </form>
                <button class="password-btn" style="margin-top: 30px; height: 40px">修改安全信息</button>
            </div>
        </div>
    </div>
    
    <%--修改密码对话框--%>
    <div id="password-dialog" title="修改安全信息" style="color: #004085">
        <form id="password-form" method="post">
            <input type="hidden" name="id" value="<%=student.getId()%>">
            <%--邮箱: &nbsp;&nbsp;<input type="email" name="email" value="<%=student.getEmail()%>"><br><br>--%>
            新密码:<input type="password" name="password"><br>
            <hr>
            <input style="float: right " type="submit" value="取消" onclick="function x() {
              $('#add-dialog').dialog('close');
            }">
            <input style="float: right; margin-right: 25px" type="submit" value="保存"
                   onclick="this.form.action='../update_student_security'">
        </form>
    </div>
    
    <script>
        $('#password-dialog').dialog({
            width: 340,
            autoOpen: false,
            draggable: false,
            modal: true,
            resizable: false
        });
        $('.password-btn').click(function () {
            $('#password-dialog').dialog('open');
        });
    </script>
    
    <style>
        .ui-dialog-titlebar-close {
            display: none
        }
    </style>
    </body>
    </html>
    
    
    

    student(resetPassword.jsp)

    <%--
      Created by IntelliJ IDEA.
      User: 007
      Date: 2018/11/28
      Time: 19:56
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>重置密码</title>
        <link rel="stylesheet" href="../resources/css/bootstrap.min.css">
        <link href="../resources/css/forget.css" type="text/css" rel="stylesheet" />
    </head>
    <body style="background: #c3e6cb">
    <h1 style="margin: 0px 80px; color:darkslateblue; font-family: STCaiyun">学生成绩管理系统</h1><br>
    
    <%
        String id = request.getParameter("id");
        String email = request.getParameter("email");
        String reset = request.getParameter("reset");
        String code = (String) session.getAttribute("reset");
        if (!reset.equals(code)){
    %>
        <script>alert("验证码错误!");window.location.href='../forget.jsp';</script>
    <%
        }
        else {
    %>
        <div class="main">
            <form role="form" action="../update_student_security" method="post">
                <div class="form-group" align="center">
                    <input class="form-control" type="text" name="password" placeholder="新密码"><br>
                    <input type="hidden" name="id" value="<%=id%>">
                    <input type="hidden" name="email" value="<%=email%>">
                    <input type="submit" class="btn btn-success" value="提交">
                    <input type="button" class="btn btn-info" value="取消" style="margin-left: 20px" onclick="window.location.href='../login.jsp'">
                </div>
            </form>
        </div>
    <%
        }
    %>
    <script src="../resources/js/jquery-3.2.1.min.js"></script>
    <script src="../resources/js/popper.min.js"></script>
    <script src="../resources/js/bootstrap.min.js"></script>
    </body>
    </html>
    
    

    teacher(main.jsp)

    <%@ page import="java.util.ArrayList" %>
    <%@ page import="vo.Student" %>
    <%@ page import="vo.Teacher" %>
    <%--
      Created by IntelliJ IDEA.
      User: 007
      Date: 2018/11/1
      Time: 20:11
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <!DOCTYPE html>
    <html>
    <head>
        <link rel="stylesheet" href="../resources/css/jquery-ui-1.10.4.custom.min.css">
        <script src="../resources/js/jquery-1.10.2.js"></script>
        <script src="../resources/js/jquery-ui-1.10.4.custom.min.js"></script>
        <title>main</title>
        <link href="../resources/css/default.css" rel="stylesheet"/>
    </head>
    <body style="background: #c3e6cb">
    <%
        Teacher teacher = (Teacher) session.getAttribute("info");
        ArrayList<Student> stus = (ArrayList<Student>) session.getAttribute("onePageStudent");
        int sumIndex = (int) session.getAttribute("sumIndex");
    %>
    
    
    <div id="page" class="container">
        <div id="header">
    
             logo部分
            <div id="logo">
                <img src="../userImg/<%=teacher.getId()%>.jpeg"/>
                <h1><%=teacher.getId()%>
                </h1>
            </div>
    
    
            <%-- 左面的功能栏 --%>
            <div id="menu">
                <ul>
                    <li><a href="personal.jsp">个人信息</a></li>
                    <li class="current_page_item"><a href="../one_page_student">学生信息管理</a></li>
                    <li><a href="../one_page_score">学生成绩管理</a></li>
                    <li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li>
                </ul>
            </div>
    
        </div>
        <div id="main">
            <div class="top">
                <h2 style="color: darkslateblue">学生成绩管理</h2>
                <hr/>
                <button class="btn-add" style="color: #2980b9">添加学生信息</button>
                <div class="find">
                    <form action="../one_page_student" method="post">
                        <input id="find-text" type="text" name="key" placeholder="输入学号/工号或姓名搜索">
                        <input class="find-btn" type="submit" value="搜索">
                    </form>
                </div>
            </div>
            <div class="table">
                <table id="table" width="800" frame="box" align="center">
                    <tr>
                        <th height="35">学号/工号</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>班级</th>
                        <th>学院</th>
                        <th>操作</th>
                    </tr>
                    <%
                        for (Student stu : stus) {
                    %>
                            <tr>
                                <form method="post" action="../update_student">
                                    <td height="35"><%=stu.getId()%></td>
                                    <td><input value="<%=stu.getName()%>" name="stuname" class="table-input"></td>
                                    <td><input value="<%=stu.getSex()%>" name="stusex" class="table-input"></td>
                                    <td><%=stu.getSchool_date()%></td>
                                    <td><input value="<%=stu.getMajor()%>" name="stumajor" class="table-input" style="width: 110px"></td>
                                    <input value="<%=stu.getId()%>" name="stuno" type="hidden">
                                    <td><input type="submit" class="update-btn" value="修改">&nbsp;
                                        <a class="btn-delete" onclick="return confirm('确定要删除吗?');"
                                           href=<%="'../delete_student?id=" + stu.getId() + "'"%>>删除</a>&nbsp;&nbsp;
                                        <a href="../one_page_score?id=<%=stu.getId()%>" style="color: #117a8b">学生成绩</a>
                                    </td>
                                </form>
                            </tr>
                    <%
                        }
                    %>
                </table>
            </div>
            <%
                if (sumIndex > 1){
            %>
                    <div id="index">
                        <a href="../one_page_student?index=1">首页</a>
                        <%
                            for (int i=1; i<=sumIndex; i++){
                        %>
                                <a href="../one_page_student?index=<%=i%>"><%=i%></a>
                        <%
                            }
                        %>
                        <a href="../one_page_student?index=<%=sumIndex%>">尾页</a>
                    </div>
            <%
                }
            %>
        </div>
    </div>
    
    <%--添加学生信息对话框--%>
    <div id="add-dialog" title="添加学生信息">
        <form id="add-form" method="post">
            学号:<input name="id" type="text"><br>
            姓名:<input name="name" type="text"><br>
            性别:<input name="sex" type="text"><br>
            班级:<input name="school_date" type="text">
            学院:<input name="major" type="text"><br>
    
            <hr>
            <input style="float: right" type="submit" value="取消" onclick="function x() {
              $('#add-dialog').dialog('close');
            }">
            <input style="float: right; margin-right: 25px" type="submit" value="确定"
                   onclick="this.form.action='../add_student'">
        </form>
    </div>
    
    <style>
        .ui-dialog-titlebar-close {
            display: none
        }
    </style>
    
    <script>
        $('#add-dialog').dialog({
            width: 310,
            autoOpen: false,
            draggable: false,
            modal: true,
            resizable: false
        });
        $('.btn-add').click(function () {
            $('#add-dialog').dialog('open');
        });
    </script>
    </body>
    </html>
    
    
    

    teacher(personal.jsp)

    <%@ page import="vo.Teacher" %>
    <%--
      Created by IntelliJ IDEA.
      User: 007
      Date: 2018/11/1
      Time: 20:11
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <!DOCTYPE html>
    <html>
    <head>
        <title>main</title>
        <link href="../resources/css/default.css" rel="stylesheet"/>
    </head>
    <body style="background: #c3e6cb">
    <%
        Teacher teacher = (Teacher) session.getAttribute("info");
    %>
    <div id="page" class="container">
        <div id="header">
            <div id="logo">
                <img src="../userImg/<%=teacher.getId()%>.jpeg"/>
                <h1><%=teacher.getId()%>
                </h1>
            </div>
            <div id="menu">
                <ul>
                    <li class="current_page_item"><a href="personal.jsp">个人信息</a></li>
                    <li><a href="../one_page_student">学生信息管理</a></li>
                    <li><a href="../one_page_score">学生成绩管理</a></li>
                    <li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li>
                </ul>
            </div>
        </div>
        <div id="main">
            <div class="top">
                <h2 style="color: darkslateblue">个人信息</h2>
                <hr/>
            </div>
            <div class="info">
                <img src="../userImg/<%=teacher.getId()%>.jpeg" class="personalImg"><br>
                <form action="../upload_teacherImg" method="post" enctype="multipart/form-data">
                    <input type="hidden" name="id" value="<%=teacher.getId()%>">
                    <input type="file" name="img">
                    <input type="submit" value="上传头像">
                </form>
                <form method="post" action="../update_teacher" class="personalForm">
                    <input name="uid" value="<%=teacher.getId()%>" type="hidden">
                    姓名: <input type="text" name="name" value="<%=teacher.getName()%>" class="personalInput"><br>
                    性别: <input type="text" name="sex" value="<%=teacher.getSex()%>" class="personalInput"><br>
                    邮箱: <input type="text" name="email" value="<%=teacher.getEmail()%>" class="personalInput"><br>
                    密码: <input type="text" name="password" value="<%=teacher.getPassword()%>" class="personalInput"><br>
                    <input type="submit" value="保存" style="width: 100px; height: 30px; margin-top: 20px">
                </form>
            </div>
        </div>
    </div>
    </body>
    </html>
    
    
    

    teacher(resetPassword.jsp)

    <%--
      Created by IntelliJ IDEA.
      User: 007
      Date: 2018/11/28
      Time: 19:56
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>重置密码</title>
        <link rel="stylesheet" href="../resources/css/bootstrap.min.css">
        <link href="../resources/css/forget.css" type="text/css" rel="stylesheet" />
    </head>
    <body>
    <h1 style="margin: 0px 80px; color:darkslateblue; font-family: STCaiyun">学生成绩管理系统</h1><br>
    
    
    <%
        String id = request.getParameter("id");
        String reset = request.getParameter("reset");
        String code = (String) session.getAttribute("reset");
        if (!reset.equals(code)){
    %>
            <script>alert("验证码错误!");window.location.href='../forget.jsp';</script>
    <%
        } else {
    %>
            <div class="main">
                <form role="form" action="../update_teacher_password" method="post">
                    <div class="form-group" align="center">
                        <input type="text" class="form-control" name="password" placeholder="新密码"><br>
                        <input type="hidden" name="id" value="<%=id%>">
                        <input type="submit" class="btn btn-success" value="提交">
                        <input type="button" class="btn btn-info" value="取消" style="margin-left: 20px" onclick="window.location.href='../login.jsp'">
                    </div>
                </form>
            </div>
    <%
        }
    %>
    <script src="../resources/js/jquery-3.2.1.min.js"></script>
    <script src="../resources/js/popper.min.js"></script>
    <script src="../resources/js/bootstrap.min.js"></script>
    </body>
    </html>
    
    

    teacher(score.jsp)

    <%@ page import="vo.Teacher" %>
    <%@ page import="vo.Score" %>
    <%@ page import="java.util.ArrayList" %>
    <%@ page import="dao.StudentDao" %>
    <%--
      Created by IntelliJ IDEA.
      User: 007
      Date: 2018/11/1
      Time: 20:11
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <!DOCTYPE html>
    <html>
    <head>
        <title>main</title>
        <link href="../resources/css/default.css" rel="stylesheet"/>
    </head>
    <body style="background: #c3e6cb">
    <%
        Teacher teacher = (Teacher) session.getAttribute("info");
        ArrayList<Score> stus = (ArrayList<Score>) session.getAttribute("onePageScore");
        int sumIndex = (int) session.getAttribute("sumScoreIndex");
    %>
    <div id="page" class="container">
        <div id="header">
            <div id="logo">
                <img src="../userImg/<%=teacher.getId()%>.jpeg"/>
                <h1><%=teacher.getId()%>
                </h1>
            </div>
            <div id="menu">
                <ul>
                    <li><a href="personal.jsp">个人信息</a></li>
                    <li><a href="../one_page_student">学生信息管理</a></li>
                    <li class="current_page_item"><a href="../one_page_score">学生成绩管理</a></li>
                    <li><a onclick="return confirm('确认退出?');" href="../exit">退出登录</a></li>
                </ul>
            </div>
        </div>
        <div id="main">
            <div class="top">
                <h2 style="color: darkslateblue">学生成绩管理</h2>
                <hr/>
            </div>
            <form method="post" action="../update_score" style="height: 525px; margin-top: 20px">
                <input type="button" class="btn-add" onclick="location.href='score_excel.jsp';" value="导出EXCEL">
                <input type="submit" class="btn-add" style="float: right;margin-bottom: 30px" value="修改">
                <div class="table" style="margin-top: 20px; height: 525px">
                    <table id="table" width="800" frame="box" align="center">
                        <tr>
                            <th height="35">学号</th>
                            <th>姓名</th>
                            <th>学院</th>
                            <th>数据库</th>
                            <th>安卓</th>
                            <th>JSP</th>
                        </tr>
                        <%
                            try {
                                StudentDao stuD = new StudentDao();
                                for (Score stu : stus) {
                                    String name = stuD.findWithId(stu.getId()).getName();
                                    String major = stuD.findWithId(stu.getId()).getMajor();
                        %>
                        <tr>
                            <td height="35"><%=stu.getId()%></td>
                            <td><%=name%></td>
                            <td><%=major%></td>
                            <td><input value="<%=stu.getDatabase()%>" name="database" class="table-input"></td>
                            <td><input value="<%=stu.getAndroid()%>" name="android" class="table-input"></td>
                            <td><input value="<%=stu.getJsp()%>" name="jsp" class="table-input"></td>
                            <input value="<%=stu.getId()%>" name="id" type="hidden">
                        </tr>
                        <%
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        %>
                    </table>
    
                </div>
            </form>
            <%-- 展示下面的页签数 --%>
            <%
                if (sumIndex > 1){
            %>
                    <div id="index">
                        <a href="../one_page_score?index=1">首页</a>
                        <%
                            for (int i = 1; i <= sumIndex; i++) {
                        %>
                        <a href="../one_page_score?index=<%=i%>"><%=i%></a>
                        <%
                            }
                        %>
                        <a href="../one_page_score?index=<%=sumIndex%>">尾页</a>
                    </div>
            <%
                }
            %>
        </div>
    </div>
    </body>
    </html>
    
    
    

    teacher(score_excel.jsp)

    <%@ page import="dao.ScoreDao" %>
    <%@ page import="vo.Score" %>
    <%@ page import="java.util.ArrayList" %>
    <%@ page import="dao.StudentDao" %>
    <%--
      Created by IntelliJ IDEA.
      User: 007
      Date: 2018/11/1
      Time: 20:11
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="application/msexcel" language="java" pageEncoding="UTF-8" %>
    <!DOCTYPE html>
    <html>
    <head>
        <title>main</title>
    </head>
    <body style="background: #c3e6cb">
    <%
        out.clearBuffer();
        response.setHeader("Content-Disposition", "attachment;filename=excel.xls");
    %>
    <table align="center" border="1">
        <tr>
            <th height="35">学号</th>
            <th>姓名</th>
            <th>学院</th>
            <th>数据库</th>
            <th>安卓</th>
            <th>JSP</th>
        </tr>
        <%
            try {
                ScoreDao scoD = new ScoreDao();
                StudentDao stuD = new StudentDao();
                ArrayList<Score> stus = scoD.getOnePage(1, 10000);
                for (Score stu : stus) {
                    String name = stuD.findWithId(stu.getId()).getName();
                    String major = stuD.findWithId(stu.getId()).getMajor();
        %>
        <tr>
                <td align="center"><%=stu.getId()%></td>
                <td align="center"><%=name%></td>
                <td align="center"><%=major%></td>
                <td align="center"><%=stu.getDatabase()%></td>
                <td align="center"><%=stu.getAndroid()%></td>
                <td align="center"><%=stu.getJsp()%></td>
        </tr>
        <%
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        %>
    </table>
    </body>
    </html>
    
    
    

    code.jsp

    <%@ page import="java.awt.image.BufferedImage" %>
    <%@ page import="java.awt.*" %>
    <%@ page import="java.util.Random" %>
    <%@ page import="javax.imageio.ImageIO" %>
    <%--
      Created by IntelliJ IDEA.
      User: 007
      Date: 2018/11/22
      Time: 18:48
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="image/JPEG;charset=UTF-8" pageEncoding="UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
    </head>
    <body>
    <%
        response.setCharacterEncoding("utf-8");
    
        response.setHeader("Cache-Control", "no-cache");
        //创建图像
        int width = 60, height = 20;
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        //获取画笔
        Graphics g = image.getGraphics();
        //设定背景色
        g.setColor(new Color(100, 200, 200));
        g.fillRect(0, 0, width, height);
        //随机产生四位数字
        Random rnd = new Random();
        int randNum = rnd.nextInt(8999) + 1000;
        String randStr = String.valueOf(randNum);
        //将验证码存入session
        session.setAttribute("randStr", randStr);
        //显示到图像中
        g.setColor(Color.BLACK);
        g.setFont(new Font("", Font.PLAIN, 20));
        g.drawString(randStr, 10, 17);
        //随机产生100个干扰点
        for (int i = 0; i < 100; i++) {
            int x = rnd.nextInt(width);
            int y = rnd.nextInt(height);
            g.drawOval(x, y, 1, 1);
        }
        //输出到页面
        ImageIO.write(image, "jpeg", response.getOutputStream());
        out.clear();
        out = pageContext.pushBody();
    %>
    </body>
    </html>
    
    

    login.jsp

    <%--
      Created by IntelliJ IDEA.
      User: 007
      Date: 2018/11/1
      Time: 20:16
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>请登陆</title>
        <link rel="stylesheet" href="resources/css/bootstrap.min.css">
        <link href="resources/css/login.css" type="text/css" rel="stylesheet" />
    
    </head>
    <body>
    <script>
        function check(form){
            if (form.user.value === "") {
                alert("请输入账号!");
                return false;
            }
            if (form.password.value === "") {
                alert("请输入密码!");
                return false;
            }
            return true;
        }
    
    </script>
    <h1>学生成绩管理系统</h1><br>
    
    
    
    <div class="main">
        <h5 class="title">
            <a href="login.jsp" id="login">登录</a>
            <b>&nbsp;·&nbsp;</b>
            <a href="register.jsp" id="register">注册</a>
        </h5>
        <form action="check_login" method="post" onsubmit="return check(this)">
            <div class="form-group" >
                <input type="text" name="user" class="form-control user" placeholder="请输入用户名">
                <input type="password" name="password" class="form-control password" placeholder="请输入密码">
                <div class="remember-btn">
                    <input type="checkbox" name="remember" value="true">
                    <span style="color: #d4edda">记住我</span>
                </div>
                <%--<a href="forget.jsp" class="help" style="color: #1b1e21">登录遇到问题?</a>--%>
                <input type="submit" value="登录" class="btn btn-primary btn-lg btn-block" />
            </div>
        </form>
    </div>
    <script src="resources/js/jquery-3.2.1.min.js"></script>
    <script src="resources/js/popper.min.js"></script>
    <script src="resources/js/bootstrap.min.js"></script>
    </body>
    </html>
    

    register.jsp

    <%--
      Created by IntelliJ IDEA.
      User: 007
      Date: 2018/11/1
      Time: 20:26
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>注册</title>
        <link rel="stylesheet" href="resources/css/bootstrap.min.css">
        <link href="resources/css/register.css" type="text/css" rel="stylesheet" />
    </head>
    <body>
    <script>
        function check(form){
            if (form.user.value === "") {
                alert("请输入账号!");
                return false;
            }
            if (form.password1.value === "") {
                alert("请输入密码!");
                return false;
            }
            return true;
        }
        
        function refresh() {
            var i=Math.random();
            document.getElementById("image").src = "code.jsp?a="+i;
        }
    </script>
    <h1>学生成绩管理系统</h1><br>
    
    <div class="main">
        <h5 class="title" >
            <a href="login.jsp" id="login">登录</a>
            <b>&nbsp;·&nbsp;</b>
            <a href="register.jsp" id="register">注册</a>
        </h5>
        <form action="check_register" method="post" onsubmit="return check(this)">
            <div class="form-group">
                <input type="email" name="email" class="form-control email" placeholder="安全邮箱">
                <input type="text" name="user" class="form-control user" placeholder="用户名">
                <input type="password" name="password1" class="form-control password1" placeholder="密码">
                <input type="text" name="code" placeholder="验证码" class="code">
                <img src="code.jsp" id="image" style="float: right; width: 90px;height: 50px; margin-top: 10px" onclick="refresh()">
                <input type="submit" value="注册" class="btn btn-primary btn-lg btn-block we" />
            </div>
        </form>
    </div>
    <script src="resources/js/jquery-3.2.1.min.js"></script>
    <script src="resources/js/popper.min.js"></script>
    <script src="resources/js/bootstrap.min.js"></script>
    </body>
    </html>
    
    

    2.后端

    Score

    package vo;
    
    /**
     * 分数类
     */
    
    public class Score {
    
        private String id;
        private String database;
        private String android;
        private String jsp;
    
        public String getId(){
            return id;
        }
    
        public String getDatabase(){
            return database;
        }
    
        public String getAndroid(){
            return android;
        }
    
        public String getJsp(){
            return jsp;
        }
    
        public void setId(String id){
            this.id = id;
        }
    
        public void setDatabase(String database){
            this.database = database;
        }
    
        public void setAndroid(String android){
            this.android = android;
        }
    
        public void setJsp(String jsp){
            this.jsp = jsp;
        }
    }
    
    

    Student

    package vo;
    
    import java.sql.Date;
    import java.sql.PseudoColumnUsage;
    import java.util.regex.Pattern;
    
    /**
     *学生类
     */
    
    public class Student {
    
        private String id;
        private String password;
        private String name;
        private String sex;
        private String school_date;
        private String major;
        private String email;
    
        public String getId(){
            return id;
        }
    
        public String getPassword(){
            return password;
        }
    
        public String getName(){
            return name;
        }
    
        public String getSex(){
            return sex;
        }
    
        public String getSchool_date(){
            return school_date;
        }
    
        public String getMajor(){
            return major;
        }
    
        public String getEmail(){
            return email;
        }
    
        public void setId(String id){
            this.id = id;
        }
    
        public void setPassword(String password){
            this.password = password;
        }
    
        public void setName(String name){
            this.name = name;
        }
    
        public void setSex(String sex){
            this.sex = sex;
        }
    
        public void setSchool_date(String school_date){
            this.school_date = school_date;
        }
    
        public void setMajor(String major){
            this.major = major;
        }
    
        public void setEmail(String email){
            this.email = email;
        }
    }
    
    

    Teacher

    package vo;
    
    /**
     * 教师类
     */
    
    public class Teacher {
    
        private String id;
        private String password;
        private String email;
        private String name;
        private String sex;
    
        public String getId(){
            return id;
        }
    
        public String getPassword(){
            return password;
        }
    
        public String getEmail(){
            return email;
        }
    
        public String getName(){
            return name;
        }
    
        public String getSex(){
            return sex;
        }
    
        public void setId(String id){
            this.id = id;
        }
    
        public void setPassword(String password){
            this.password = password;
        }
    
        public void setEmail(String email){
            this.email= email;
        }
    
        public void setName(String name){
            this.name = name;
        }
    
        public void setSex(String sex){
            this.sex = sex;
        }
    
    }
    
    

    ScoreDao

    package dao;
    
    import vo.Score;
    
    import java.sql.*;
    import java.util.ArrayList;
    
    public class ScoreDao {
    
        private Connection conn = null;
        // 定义数据常量
        static String driver = "com.mysql.cj.jdbc.Driver";
        static String url = "jdbc:mysql://localhost:3306/student_manager?serverTimezone=UTC";
        static String user = "root";
        static String password="admin";
    
        /**
         * 录入成绩
         * @param id
         * @return
         * @throws Exception
         */
        public boolean insertScore(String id) throws Exception{
            initConnection();
            String sql = "insert into score(id) values(?)";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, id);
            int i = ps.executeUpdate();
            closeConnection();
            return i == 1;
        }
    
        /**
         * 删除成绩
         * @param id
         * @return
         * @throws Exception
         */
        public boolean deleteScore(String id) throws Exception{
            initConnection();
            Statement stat = conn.createStatement();
            String sql = "delete from score where id='"+id+"'";
            int i = stat.executeUpdate(sql);
            closeConnection();
            return i==1;
        }
    
        /**
         * 更新成绩
         * @param id
         * @param database
         * @param android
         * @param jsp
         * @throws Exception
         */
        public void updateScoreInfo(String id, String database, String android, String jsp) throws Exception{
    
            initConnection();
            String sql = "update score set dat=?, android=?, jsp=? where id=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, database);
            ps.setString(2, android);
            ps.setString(3, jsp);
            ps.setString(4, id);
            ps.executeUpdate();
            closeConnection();
        }
    
        /**
         * 以id查找信息
         * @param id
         * @return
         * @throws Exception
         */
        public Score findWithId(String id) throws Exception{
            initConnection();
            Statement stat = conn.createStatement();
            String sql = "select * from score where id = '" + id + "'";
            ResultSet rs = stat.executeQuery(sql);
            Score stu = getScore(rs);
            closeConnection();
            return stu;
        }
    
        /**
         * 分页查询
         * @param page
         * @param size
         * @return
         * @throws Exception
         */
        public ArrayList<Score> getOnePage(int page, int size) throws Exception{
            ArrayList<Score> al = new ArrayList<>();
            initConnection();
            String sql = "SELECT * FROM score limit ?, ?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setInt(1, (page-1)*size);
            ps.setInt(2, size);
            ResultSet rs =  ps.executeQuery();
            getMoreScore(al, rs);
            closeConnection();
            return al;
        }
    
        /**
         * 查询总数
         * @return
         * @throws Exception
         */
        public int getScoreCount() throws Exception{
            initConnection();
            String sql = "select count(*) from score";
            Statement stat = conn.createStatement();
            ResultSet rs = stat.executeQuery(sql);
            rs.next();
            int count = rs.getInt(1);
            closeConnection();
            return count;
        }
    
        /**
         * 获取成绩
         * @param rs
         * @return
         * @throws SQLException
         */
        private Score getScore(ResultSet rs) throws SQLException {
            Score stu = null;
            if (rs.next()){
                stu = new Score();
                stu.setId(rs.getString("id"));
                stu.setDatabase(rs.getString("dat"));
                stu.setAndroid(rs.getString("android"));
                stu.setJsp(rs.getString("jsp"));
            }
            return stu;
        }
    
        /**
         * 获取所有成绩
         * @param al
         * @param rs
         * @throws SQLException
         */
        private void getMoreScore(ArrayList<Score> al, ResultSet rs) throws SQLException {
            while (rs.next()){
                Score score = new Score();
                score.setId(rs.getString("id"));
                score.setDatabase(rs.getString("dat"));
                score.setAndroid(rs.getString("android"));
                score.setJsp(rs.getString("jsp"));
                al.add(score);
            }
        }
    
        /**
         * 初始化数据库连接
         * @throws Exception
         */
        private void initConnection() throws Exception {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, user, password);
        }
    
        /**
         * 关闭连接
         * @throws Exception
         */
        private void closeConnection() throws Exception{
            conn.close();
        }
    }
    
    

    StudentDao

    package dao;
    
    import vo.Student;
    
    import java.sql.*;
    import java.util.ArrayList;
    
    /**
     * @author shuijianshiqing
     * @date 2020/6/11 20:40
     * 操作教师信息
     */
    
    public class StudentDao {
    
        private Connection conn = null;
        // 定义数据常量
        static String driver = "com.mysql.cj.jdbc.Driver";
        static String url = "jdbc:mysql://localhost:3306/student_manager?serverTimezone=UTC";
        static String user = "root";
        static String password="admin";
    
        /**
         * 验证学生账号和密码
         * @param user
         * @param password
         * @return
         * @throws Exception
         */
        public Student checkAccount(String user, String password) throws Exception {
            initConnection();
            Statement stat = conn.createStatement();
            String sql = "select * from student where id = '" + user + "' and password = '" + password + "'";
            ResultSet rs = stat.executeQuery(sql);
            Student stu = getStudent(rs);
            closeConnection();
            return stu;
        }
    
        /**
         * 使用学生id来查找学生信息
         * @param id
         * @return
         * @throws Exception
         */
        public Student findWithId(String id) throws Exception{
            initConnection();
            Statement stat = conn.createStatement();
            String sql = "select * from student where id = '" + id + "'";
            ResultSet rs = stat.executeQuery(sql);
            Student stu = getStudent(rs);
            closeConnection();
            return stu;
        }
    
        /**
         * 使用学生姓名查找学生信息
         * @param name
         * @return
         * @throws Exception
         */
        public ArrayList<Student> findWithName(String name) throws Exception{
            ArrayList<Student> al = new ArrayList<>();
            initConnection();
            Statement stat = conn.createStatement();
            String sql = "select * from student where name = '" + name + "'";
            ResultSet rs = stat.executeQuery(sql);
            getMoreStudent(al, rs);
            closeConnection();
            return al;
        }
    
        /**
         * 添加学生信息
         * @param id
         * @param name
         * @param sex
         * @param school_date
         * @param major
         * @return
         * @throws Exception
         */
        public boolean insertStudent(String id, String name, String sex, String school_date, String major) throws Exception{
            initConnection();
            String sql = "insert into student(id, name, sex, school_date, major) values(?, ?, ?, ?, ?)";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, id);
            ps.setString(2, name);
            ps.setString(3, sex);
            ps.setString(4, school_date);
            ps.setString(5, major);
            int i = ps.executeUpdate();
            closeConnection();
            return i == 1;
        }
    
        /**
         * 删除学生信息
         * @param id
         * @return
         * @throws Exception
         */
        public boolean deleteStudent(String id) throws Exception{
            initConnection();
            Statement stat = conn.createStatement();
            String sql = "delete from student where id='"+id+"'";
            int i = stat.executeUpdate(sql);
            closeConnection();
            return i==1;
        }
    
        /**
         * 获取每页的信息
         * @param page
         * @param size
         * @return
         * @throws Exception
         */
        public ArrayList<Student> getOnePage(int page, int size) throws Exception{
            ArrayList<Student> al = new ArrayList<>();
            initConnection();
            String sql = "SELECT * FROM student limit ?, ?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setInt(1, (page-1)*size);
            ps.setInt(2, size);
            ResultSet rs =  ps.executeQuery();
            getMoreStudent(al, rs);
            closeConnection();
            return al;
        }
    
        /**
         * 获取学生总数
         * @return
         * @throws Exception
         */
        public int getStudentCount() throws Exception{
            initConnection();
            String sql = "select count(*) from student";
            Statement stat = conn.createStatement();
            ResultSet rs = stat.executeQuery(sql);
            rs.next();
            int count = rs.getInt(1);
            closeConnection();
            return count;
        }
    
        /**
         * 更新学生信息
         * @param id
         * @param name
         * @param sex
         * @param major
         * @throws Exception
         */
        public void updateStudentInfo(String id, String name, String sex, String major) throws Exception{
    
            initConnection();
            String sql = "update student set name=?, sex=?, major=? where id=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, name);
            ps.setString(2, sex);
            ps.setString(3, major);
            ps.setString(4, id);
            ps.executeUpdate();
            closeConnection();
        }
    
        /**
         * 更新学生密码和邮件
         * @param id
         * @param email
         * @param password
         * @throws Exception
         */
        public void updateStudentSecurity(String id, String email, String password) throws Exception{
    
            initConnection();
            String sql = "update student set password=?, email=? where id=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, password);
            ps.setString(2, email);
            ps.setString(3, id);
            ps.executeUpdate();
            closeConnection();
        }
    
        /**
         * 获取单个学生信息
         * @param rs
         * @return
         * @throws SQLException
         */
        private Student getStudent(ResultSet rs) throws SQLException {
            Student stu = null;
            if (rs.next()){
                stu = new Student();
                stu.setId(rs.getString("id"));
                stu.setPassword(rs.getString("password"));
                stu.setName(rs.getString("name"));
                stu.setSex(rs.getString("sex"));
                stu.setSchool_date(rs.getString("school_date"));
                stu.setMajor(rs.getString("major"));
                stu.setEmail(rs.getString("email"));
            }
            return stu;
        }
    
        /**
         * 获取多个学生信息
         * @param al
         * @param rs
         * @throws SQLException
         */
        private void getMoreStudent(ArrayList<Student> al, ResultSet rs) throws SQLException {
            while (rs.next()){
                Student stu = new Student();
                stu.setId(rs.getString("id"));
                stu.setPassword(rs.getString("password"));
                stu.setName(rs.getString("name"));
                stu.setSex(rs.getString("sex"));
                stu.setSchool_date(rs.getString("school_date"));
                stu.setMajor(rs.getString("major"));
                stu.setEmail(rs.getString("email"));
                al.add(stu);
            }
        }
    
        /**
         * 初始化数据库连接
         * @throws Exception
         */
        private void initConnection() throws Exception {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, user, password);
        }
    
        /**
         * 关闭连接
         * @throws Exception
         */
        private void closeConnection() throws Exception{
            conn.close();
        }
    }
    
    

    TeacherDao

    package dao;
    
    import vo.Teacher;
    
    import java.sql.*;
    
    /**
     * @author shuijianshiqing
     * @date 2020/6/11 20:40
     * 操作教师信息
     */
    
    public class TeacherDao {
    
        // 定义连接
        private Connection conn = null;
        // 定义数据常量
        static String driver = "com.mysql.cj.jdbc.Driver";
        static String url = "jdbc:mysql://localhost:3306/student_manager?serverTimezone=UTC";
        static String user = "root";
        static String password="admin";
    
        /**
         * 验证教师登录的账号和密码
         * @param id
         * @param password
         * @return
         * @throws Exception
         */
        public Teacher checkAccount(String id, String password) throws Exception {
            initConnection();
            Statement stat = conn.createStatement();
            String sql = "select * from teacher where id = '" + id + "' and password = '" + password + "'";
            ResultSet rs = stat.executeQuery(sql);
            Teacher tea = getTeacher(rs);
            closeConnection();
            return tea;
        }
    
        /**
         * 使用教师id来查询教师信息
         * @param id
         * @return
         * @throws Exception
         */
        public Teacher findWithId(String id) throws Exception {
            initConnection();
            Statement stat = conn.createStatement();
            String sql = "select * from teacher where id = '" + id + "'";
            ResultSet rs = stat.executeQuery(sql);
            Teacher tea = getTeacher(rs);
            closeConnection();
            return tea;
        }
    
        /**
         * 添加教师信息
         * @param id
         * @param password
         * @param email
         * @return
         * @throws Exception
         */
        public Teacher insertTeacher(String id, String password, String email) throws Exception {
            initConnection();
            String sql = "insert into teacher(id, password, email) values(?, ?, ?)";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, id);
            ps.setString(2, password);
            ps.setString(3, email);
            ps.executeUpdate();
            Teacher teacher = findWithId(id);
            closeConnection();
            return teacher;
        }
    
        /**
         * 更新教师信息
         * @param id
         * @param name
         * @param sex
         * @param email
         * @param password
         * @return
         * @throws Exception
         */
        public Teacher updateTeacher(String id, String name, String sex, String email, String password) throws Exception{
    
            initConnection();
            String sql = "update teacher set name=?, sex=?, email=?, password=? where id=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, name);
            ps.setString(2, sex);
            ps.setString(3, email);
            ps.setString(4, password);
            ps.setString(5, id);
            ps.executeUpdate();
            Teacher teacher = findWithId(id);
            closeConnection();
            return teacher;
        }
    
        /**
         * 更新教师密码
         * @param id
         * @param password
         * @throws Exception
         */
        public void updateTeacherPassword(String id, String password) throws Exception{
    
            initConnection();
            String sql = "update teacher set password=? where id=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, password);
            ps.setString(2, id);
            ps.executeUpdate();
            closeConnection();
        }
    
        /**
         * 根据ResultSet来获取教师信息
         * @param rs
         * @return
         * @throws SQLException
         */
        private Teacher getTeacher(ResultSet rs) throws SQLException {
            Teacher tea = null;
            if (rs.next()) {
                tea = new Teacher();
                tea.setId(rs.getString("id"));
                tea.setPassword(rs.getString("password"));
                tea.setName(rs.getString("name"));
                tea.setEmail(rs.getString("email"));
                tea.setSex(rs.getString("sex"));
            }
            return tea;
        }
    
        /**
         * 初始化数据库连接
         * @throws Exception
         */
        private void initConnection() throws Exception {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, user, password);
        }
    
        /**
         * 关闭连接
         * @throws Exception
         */
        private void closeConnection() throws Exception {
            conn.close();
        }
    
        /**
         * 测试数据库连接
         * @param args
         */
        public static void main(String[] args) throws Exception{
            TeacherDao dao = new TeacherDao();
            dao.initConnection();
            System.out.println("数据库连接成功");
            dao.closeConnection();
        }
    }
    
    

    add_student

    package servlet;
    
    import dao.ScoreDao;
    import dao.StudentDao;
    import dao.StudentDao;
    
    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 java.io.IOException;
    import java.io.PrintWriter;
    
    /**
     * 添加学生信息
     */
    
    @WebServlet("/add_student")
    public class add_student extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doGet(request, response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
    
            PrintWriter out = response.getWriter();
    
            StudentDao studentDao = new StudentDao();
            ScoreDao scoreDao = new ScoreDao();
    
            String id = request.getParameter("id");
            String name = request.getParameter("name");
            String sex = request.getParameter("sex");
            String major = request.getParameter("major");
            String school_date = request.getParameter("school_date");
    
            try {
                // 添加学生信息
                studentDao.insertStudent(id, name, sex, school_date, major);
                // 添加分数信息
                scoreDao.insertScore(id);
            }
            catch (Exception e){
                out.print(e);
            }
            response.sendRedirect("one_page_student");
        }
    }
    
    

    check_login

    package servlet;
    
    import dao.StudentDao;
    import dao.TeacherDao;
    import vo.Student;
    import vo.Teacher;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.*;
    import java.io.IOException;
    import java.io.PrintWriter;
    
    /**
     * 检查登录
     */
    
    @WebServlet("/check_login")
    public class check_login extends HttpServlet {
    
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            this.doGet(request, response);
        }
    
        protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
    
            PrintWriter out = response.getWriter();
            HttpSession session = request.getSession();
    
            // 账号
            String user = request.getParameter("user");
            // 密码
            String password = request.getParameter("password");
            // 是否记住密码
            String remember = request.getParameter("remember");
    
            // 创建Dao层
            TeacherDao teacherDao = new TeacherDao();
            StudentDao studentDao = new StudentDao();
    
            // 创建实体类
            Teacher teacher = null;
            Student student = null;
    
            try {
                // 判断用户身份
                teacher = teacherDao.checkAccount(user, password);
                student = studentDao.checkAccount(user, password);
            }
            catch (Exception e) {
                out.print(e);
            }
    
            if (teacher != null) {
                //向session中添加用户信息
                session.setAttribute("info", teacher);
    
                //检查用户是否需要保持登录状态
                if (remember != null) {
                    //发送cookie到客户端
                    Cookie userCookie = new Cookie("name", user);
                    userCookie.setMaxAge(10);
                    response.addCookie(userCookie);
                }
                // 重定向
                response.sendRedirect("one_page_student");
            }
            else if (student != null){
                //向session中添加用户信息
                session.setAttribute("info", student);
    
                //检查用户是否需要保持登录状态
                if (remember != null) {
                    //发送cookie到客户端
                    Cookie userCookie = new Cookie("name", user);
                    userCookie.setMaxAge(10);
                    response.addCookie(userCookie);
                }
                response.sendRedirect("student/main.jsp");
            }
            else {
                out.print("<script>alert(\"用户名或密码错误!\");");
            }
        }
    }
    
    

    check_register

    package servlet;
    
    import dao.TeacherDao;
    import vo.Teacher;
    
    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 javax.servlet.http.HttpSession;
    import java.io.IOException;
    import java.io.PrintWriter;
    
    /**
     * 检查注册
     */
    
    @WebServlet("/check_register")
    public class check_register extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
    
            String email = request.getParameter("email");
            String user = request.getParameter("user");
            String password = request.getParameter("password1");
            String code = request.getParameter("code");
    
            PrintWriter out = response.getWriter();
            HttpSession session = request.getSession();
    
            String randStr = (String) session.getAttribute("randStr");
    
            if (!code.equals(randStr)) {
                out.print("<script>alert(\"验证码错误!\");location.href = \"register.jsp\";</script>");
            } else {
    
                TeacherDao teacherDao = new TeacherDao();
                Teacher teacher = null;
    
                try {
                    teacher = teacherDao.insertTeacher(user, password, email);
                } catch (Exception e) {
                    out.print(e);
                }
                if (teacher != null) {
                    //向session中添加用户信息
                    session.setAttribute("info", teacher);
                    response.sendRedirect("one_page_student");
                } else {
                    out.print("<script>alert(\"此用户已经注册!\");location.href = \"register.jsp\";</script>");
                }
            }
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
        }
    }
    
    

    delete_student

    package servlet;
    
    import dao.ScoreDao;
    import dao.StudentDao;
    import dao.StudentDao;
    
    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 java.io.IOException;
    import java.io.PrintWriter;
    
    /**
     * 删除学生信息
     */
    
    @WebServlet("/delete_student")
    public class delete_student extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
    
            PrintWriter out = response.getWriter();
            StudentDao studentDao = new StudentDao();
            ScoreDao scoreDao = new ScoreDao();
    
            String id = request.getParameter("id");
            try {
                // 删除学生
                studentDao.deleteStudent(id);
                // 删除成绩
                scoreDao.deleteScore(id);
                response.sendRedirect("one_page_student");
            }
            catch (Exception e){
                out.print(e);
            }
        }
    }
    
    

    exit

    package servlet;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.Cookie;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.IOException;
    
    /**
     * 退出登录
     */
    
    @WebServlet("/exit")
    public class exit extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            //清除cookie, 跳到起始页
            Cookie[] cookies = request.getCookies();
            if (cookies != null) {
                for (Cookie c : cookies) {
                    String cookieName = c.getName();
                    if ("name".equals(cookieName)) {
                        c.setMaxAge(0);
                        response.addCookie(c);
                    }
                }
            }
            response.sendRedirect("index.jsp");
        }
    }
    

    one_page_score

    package servlet;
    
    import dao.ScoreDao;
    import vo.Score;
    
    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 javax.servlet.http.HttpSession;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.ArrayList;
    
    /**
     * 分数分页
     */
    
    @WebServlet("/one_page_score")
    public class one_page_score extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            this.doGet(request, response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
    
            PrintWriter out = response.getWriter();
            HttpSession session = request.getSession();
    
            // 获取传入id的值
            String key = request.getParameter("id");
    
            if (key == null) {
    
                int currentIndex, count, size = 10;
                String index = request.getParameter("index");
                if (index == null)
                    index = "1";
                currentIndex = Integer.parseInt(index);
    
                try {
                    ScoreDao scoD = new ScoreDao();
                    count = scoD.getScoreCount();
                    ArrayList<Score> stus = scoD.getOnePage(currentIndex, size);
                    int sumIndex = count % size == 0 ? count / size : count / size + 1;
                    session.setAttribute("onePageScore", stus);
                    session.setAttribute("sumScoreIndex", sumIndex);
                    response.sendRedirect("teacher/score.jsp");
                } catch (Exception e) {
                    out.print(e);
                }
            }
            else {
                ScoreDao scoreDao = new ScoreDao();
                    try {
                        Score score = scoreDao.findWithId(key);
                        ArrayList<Score> scores = new ArrayList<>();
                        scores.add(score);
                        session.setAttribute("onePageScore", scores);
                        session.setAttribute("sumScoreIndex", 1);
                        response.sendRedirect("teacher/score.jsp");
                    } catch (Exception e) {
                        out.print(e);
                    }
                }
            }
    }
    
    

    one_page_student

    package servlet;
    
    import dao.StudentDao;
    import vo.Student;
    
    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 javax.servlet.http.HttpSession;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.ArrayList;
    import java.util.regex.Pattern;
    
    /**
     *学生分页
     */
    
    
    @WebServlet("/one_page_student")
    public class one_page_student extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            this.doGet(request, response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
    
            PrintWriter out = response.getWriter();
            HttpSession session = request.getSession();
    
            // 获取key的值
            String key = request.getParameter("key");
    
            // 如果key为空或者空字符串
            if (key == null || key.equals("")) {
                int currentIndex, count, size = 10;
                String index = request.getParameter("index");
                if (index == null)
                    index = "1";
                // 当前页赋值
                currentIndex = Integer.parseInt(index);
    
                try {
                    StudentDao sdao = new StudentDao();
                    // 查询当前页信息
                    ArrayList<Student> stus = sdao.getOnePage(currentIndex, size);
                    count = sdao.getStudentCount();
                    // 计算总页数
                    int sumIndex = count % size == 0 ? count / size : count / size + 1;
                    session.setAttribute("onePageStudent", stus);
                    session.setAttribute("sumIndex", sumIndex);
                    response.sendRedirect("teacher/main.jsp");
                } catch (Exception e) {
                    out.print(e);
                }
            }
            else {
    
                StudentDao studentDao = new StudentDao();
                // 这里前一个"\"是转义字符,后一个是字符串,这个字符串表示数字至少出现一次
                String pattern = "^\\d+";
                boolean isMatch = Pattern.matches(pattern, key);
                if (isMatch) {
                    try {
    
                        // 某个学生的信息
                        Student student = studentDao.findWithId(key);
                        ArrayList<Student> students = new ArrayList<>();
                        students.add(student);
                        session.setAttribute("onePageStudent", students);
                        session.setAttribute("sumIndex", 1);
                        response.sendRedirect("teacher/main.jsp");
                    } catch (Exception e) {
                        out.print(e);
                    }
                } else {
                    try {
                        ArrayList<Student> stus = studentDao.findWithName(key);
                        session.setAttribute("onePageStudent", stus);
                        session.setAttribute("sumIndex", 1);
                        response.sendRedirect("teacher/main.jsp");
                    } catch (Exception e) {
                        out.print(e);
                    }
                }
            }
        }
    }
    
    

    update_score

    package servlet;
    
    import dao.ScoreDao;
    
    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 java.io.IOException;
    import java.io.PrintWriter;
    
    /**
     * 更新成绩
     */
    
    @WebServlet("/update_score")
    public class update_score extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            this.doGet(request, response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
    
            PrintWriter out = response.getWriter();
            ScoreDao scoreDao = new ScoreDao();
    
            // 把要修改的值存下来
            String[] id = request.getParameterValues("id");
            String[] database = request.getParameterValues("database");
            String[] android = request.getParameterValues("android");
            String[] jsp = request.getParameterValues("jsp");
    
            try {
                // 循环去更新
                for (int i=0; i<id.length; i++) {
                    scoreDao.updateScoreInfo(id[i], database[i], android[i], jsp[i]);
                }
                response.sendRedirect("one_page_score");
            }
            catch (Exception e){
                out.print(e);
            }
        }
    }
    
    

    update_student

    package servlet;
    
    import dao.StudentDao;
    import dao.StudentDao;
    
    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 java.io.IOException;
    import java.io.PrintWriter;
    
    /**
     * 更新学生信息
     */
    
    @WebServlet("/update_student")
    public class update_student extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doGet(request, response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
    
            PrintWriter out = response.getWriter();
            StudentDao studentDao = new StudentDao();
    
            String stuno = request.getParameter("stuno");
            String stuname = request.getParameter("stuname");
            String stusex = request.getParameter("stusex");
            String stumajor = request.getParameter("stumajor");
    
            try {
                // 更新学生信息
                studentDao.updateStudentInfo(stuno, stuname, stusex, stumajor);
            }
            catch (Exception e){
                out.print(e);
            }
            response.sendRedirect("one_page_student");
        }
    }
    
    

    update_teacher

    package servlet;
    
    import dao.TeacherDao;
    import vo.Teacher;
    
    import javax.servlet.Servle