基于javaweb+mysql的jsp+servlet学生成绩管理系统(管理员、教师、学生)(java+jsp+servlet+javabean+mysql+tomcat)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

管理员:个人信息、课程管理、成绩管理、教师管理、学生管理

教师:个人信息、课程管理、成绩管理、学生信息查看

学生:人个信息管理、成绩查询

管理员

教师

学生

技术框架

JSP Servlet MySQL JDBC Tomcat CSS JavaScript bootstrap jquery

基于javaweb+mysql的JSP+Servlet学生成绩管理系统(管理员、教师、学生)(java+jsp+servlet+javabean+mysql+tomcat)

// 得到文件保存目录String realSavePath = makePath(saveFileName, savePath);// 创建一个文件输出流FileOutputStream fos = new FileOutputStream(realSavePath+ "\\" + saveFileName);// 创建一个缓冲区byte buffer[] = new byte[1024];// 判断输入流中的数据是否已经读完的标识int len = 0;// 循环将输入流读入到缓冲区中,(len=in.read(buffer))>0就表示in里面还有数据while ((len = is.read(buffer)) > 0) {// 使用FileOutputStream输出流将缓冲区的数据写入到指定的目录(savePath + "\\"// + filename)当中fos.write(buffer, 0, len);}// 关闭输入流is.close();// 关闭输出流fos.close();// 删除处理文件上传时生成的临时文件// item.delete();message = "文件上传成功!";}}} catch (FileUploadBase.FileSizeLimitExceededException e) {e.printStackTrace();request.setAttribute("message", "单个文件超出最大值!!!");request.getRequestDispatcher("admin/fileLoadFail.jsp").forward(request, response);return;// e.printStackTrace();} catch (FileUploadBase.SizeLimitExceededException e) {e.printStackTrace();request.setAttribute("message", "上传文件的总的大小超出限制的最大值!!!");request.getRequestDispatcher("admin/fileLoadFail.jsp").forward(request, response);return;} catch (Exception e) {message = "文件上传失败!";e.printStackTrace();}
if(cos==null){int rs=courseServiceImpl.addCos(course,coDate);if(rs>0){request.setAttribute("msg", "添加成功!!");servletFindAllCos.doGet(request, response);//request.getRequestDispatcher("admin/addCourse.jsp").forward(request, response);}else{request.setAttribute("msg", "添加失败!!");request.getRequestDispatcher("admin/addCourse.jsp").forward(request, response);}}else{request.setAttribute("msg", "该课程已录入,请重新输入!!");request.getRequestDispatcher("admin/addCourse.jsp").forward(request, response);}}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doGet(request, response);}}public class ServletEditCos extends HttpServlet{private Course course;private ServletFindAllCos servletFindAllCos=new ServletFindAllCos();private ServletSelectCos selectOne=new ServletSelectCos();private CourseServiceImpl courseServiceImpl=new CourseServiceImpl();public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
public class ServletRegistersStudent extends HttpServlet{private User user;private Student student;private UserServiceImpl userServiceImpl = new UserServiceImpl();private StudentServiceImpl studentServiceImpl =new StudentServiceImpl();@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {doPost(req, resp);}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {String stuNum = request.getParameter("stuNum");String stuName = request.getParameter("stuName");String pwd = request.getParameter("password");String stuSex = request.getParameter("stuSex");int stuAge = Integer.parseInt(request.getParameter("stuAge"));String stuClass = request.getParameter("stuClass");String major = request.getParameter("major");String department = request.getParameter("department");String phone = request.getParameter("phone");int roleID = Integer.parseInt(request.getParameter("role"));user = new User(stuNum, stuName, pwd, phone, roleID);student = new Student(stuNum, stuName, stuSex, stuAge, stuClass, major,department);int rsUser=userServiceImpl.addUser(user);int rsStu=studentServiceImpl.addStu(student);if(rsStu>0 && rsUser>0){
public class ServletaddStudent extends HttpServlet {private User user;private Student student;private UserServiceImpl userServiceImpl = new UserServiceImpl();private StudentServiceImpl studentServiceImpl =new StudentServiceImpl();private ServletFindAllStu findStu=new ServletFindAllStu();public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {String stuNum = request.getParameter("stuNum");String stuName = request.getParameter("stuName");String pwd = request.getParameter("password");String stuSex = request.getParameter("stuSex");int stuAge = Integer.parseInt(request.getParameter("stuAge"));String stuClass = request.getParameter("stuClass");String major = request.getParameter("major");String department = request.getParameter("department");String phone = request.getParameter("phone");int roleID = Integer.parseInt(request.getParameter("role"));user = new User(stuNum, stuName, pwd, phone, roleID);student = new Student(stuNum, stuName, stuSex, stuAge, stuClass, major,department);//验证是否存在该学生User rs=userServiceImpl.login(user);if(rs.getUserID()==0){int rsUser=userServiceImpl.addUser(user);int rsStu=studentServiceImpl.addStu(student);if(rsStu>0 && rsUser>0){request.setAttribute("msg", "添加成功!!");findStu.doGet(request, response);/*List list=studentDaoImpl.findAll();request.setAttribute("list", list);request.getRequestDispatcher("admin/studentAllInfo.jsp").forward(request, response);*/}else{request.setAttribute("msg", "添加失败!!");request.getRequestDispatcher("admin/addStudent.jsp").forward(request, response);}}else{request.setAttribute("msg", "该学号已存在,请重新录入!!");request.getRequestDispatcher("admin/addStudent.jsp").forward(request, response);}}
}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doGet(request, response);}}public class ServletListFile extends HttpServlet{@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {doPost(req, resp);}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {//获取上传文件的目录String uploadFilePath=this.getServletContext().getRealPath("/WEB-INF/upload");//存储要下载的文件名Map<String,String> fileNameMap=new HashMap<String, String>();/* * 递归遍历filepath目录下的所有文件和目录,将文件的文件名存储到map集合中 *///file既可以代表一个文件也可以代表一个目录listFile(new File(uploadFilePath),fileNameMap);//将map集合发送到listFile.jsp页面进行显示request.setAttribute("fileNameMap", fileNameMap);request.getRequestDispatcher("admin/fileList.jsp").forward(request, response);}private void listFile(File file, Map<String, String> fileNameMap) {//如果file代表的不是一个文件,而是一个目录if(!file.isFile()){//列出该目录下的所有文件和目录File files[]=file.listFiles();
public class ServletEditTeacherInfo extends HttpServlet{private Teacher teacher;private TeacherServiceImpl teacherServiceImpl=new TeacherServiceImpl();private ServletTeacherInfo servletTeacherInfo=new ServletTeacherInfo();public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{String teaNum=request.getParameter("teaNum");String teaName = request.getParameter("teaName");String teaSex = request.getParameter("teaSex");int teaAge = Integer.parseInt(request.getParameter("teaAge"));String teaCourse = request.getParameter("teaCourse");String major = request.getParameter("major");String department = request.getParameter("department");teacher = new Teacher(teaNum, teaName, teaSex, teaAge, teaCourse, major,department);int rs=teacherServiceImpl.editTea(teacher);if(rs>0){request.setAttribute("msg", "修改成功!!");servletTeacherInfo.doGet(request, response);}else{request.setAttribute("msg", "修改失败!!");request.getRequestDispatcher("teacher/editTeacherInfo.jsp").forward(request, response);}}public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{doGet(request,response);}}
stuName=null;}if(stuClass==""){stuClass=null;}if(major==""){major=null;}*/double scoreGrade=0;score=new Score( stuNum,stuName,stuClass, courseName,scoreGrade,major);PageBean rs=scoreServiceImpl.selectStuScore(pageNo, pageCount, score);request.setAttribute("list", rs);request.setAttribute("score", score);request.getRequestDispatcher("admin/selectblurScore.jsp").forward(request, response);}}public class ServletEditUser extends HttpServlet{private User user;private ServletFindAllUser servletFindAllUser=new ServletFindAllUser();private UserServiceImpl userServiceImpl=new UserServiceImpl();public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{String userNum=request.getParameter("userNum");String userName=request.getParameter("userName");String pwd=request.getParameter("password");String phone=request.getParameter("phone");int roleID=Integer.parseInt(request.getParameter("roleID"));user=new User(userNum,userName,pwd,phone,roleID);int rs=userServiceImpl.editUser(user);if(rs>0){request.setAttribute("msg", "修改成功!!");
throws ServletException, IOException {int pageNo=1;int pageCount=1;String teaName=(String) request.getSession().getAttribute("username");String pageNoStr=request.getParameter("pageNo");String pageCountStr=request.getParameter("pageCount");if(pageNoStr!=null){pageNo=Integer.parseInt(pageNoStr);}if(pageCountStr!=null){pageCount=Integer.parseInt(pageCountStr);}String stuNum=request.getParameter("stuNum");String stuName=request.getParameter("stuName");String stuClass=request.getParameter("stuClass");score=new Score();score.setStuNum(stuNum);score.setStuName(stuName);score.setStuClass(stuClass);PageBean list=scoreServiceImpl.selectTeaScore(pageNo, pageCount, teaName,score);request.setAttribute("list", list);request.setAttribute("score", score);request.getRequestDispatcher("teacher/stuTeaScore.jsp").forward(request, response);}}
Date courseDate=null;try { courseDate = new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("courseDate"));} catch (ParseException e) {e.printStackTrace();} //System.out.println(courseDate);course=new Course(courseName,courseCredit,courseHours,courseTea,courseDate);//new Course( courseName,courseCredit,courseHours,// courseTea,courseDate);//验证是否存在该教师课程Course cos=courseServiceImpl.selectOneCos(course);if(cos==null){int rs=courseServiceImpl.addCos(course,coDate);if(rs>0){request.setAttribute("msg", "添加成功!!");servletFindAllCos.doGet(request, response);//request.getRequestDispatcher("admin/addCourse.jsp").forward(request, response);}else{request.setAttribute("msg", "添加失败!!");request.getRequestDispatcher("admin/addCourse.jsp").forward(request, response);}}else{request.setAttribute("msg", "该课程已录入,请重新输入!!");request.getRequestDispatcher("admin/addCourse.jsp").forward(request, response);}}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doGet(request, response);}}
return null;}}public class ServletaddTeacher extends HttpServlet{private User user;private Teacher teacher;private UserServiceImpl userServiceImpl = new UserServiceImpl();private TeacherServiceImpl teacherServiceImpl =new TeacherServiceImpl();private ServletFindAllTea findTea=new ServletFindAllTea();public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {String teaNum = request.getParameter("teaNum");String teaName = request.getParameter("teaName");String pwd = request.getParameter("password");String teaSex = request.getParameter("teaSex");int teaAge = Integer.parseInt(request.getParameter("teaAge"));String teaCourse = request.getParameter("teaCourse");String major = request.getParameter("major");String department = request.getParameter("department");
public class ServletEditCos extends HttpServlet{private Course course;private ServletFindAllCos servletFindAllCos=new ServletFindAllCos();private ServletSelectCos selectOne=new ServletSelectCos();private CourseServiceImpl courseServiceImpl=new CourseServiceImpl();public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {int courseID=Integer.parseInt(request.getParameter("courseID"));String courseName = request.getParameter("courseName");int courseCredit = Integer.parseInt(request.getParameter("courseCredit"));int courseHours = Integer.parseInt(request.getParameter("courseHours"));String courseTea = request.getParameter("courseTea");String coDate = request.getParameter("courseDate");Date courseDate = null;try { courseDate = new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("courseDate"));} catch (ParseException e) {e.printStackTrace();} course=new Course(courseID,courseName,courseCredit,courseHours,courseTea,courseDate);int rs=courseServiceImpl.editCos(course,coDate);if(rs>0){request.setAttribute("msg", "修改成功!!");servletFindAllCos.doGet(request, response);//request.getRequestDispatcher("admin/addCourse.jsp").forward(request, response);}else{
List rs=userDaoImpl.selectOneUser(userID);request.setAttribute("list", rs);request.getRequestDispatcher("admin/editUser.jsp").forward(request, response);*/}public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{doGet(request,response);}}public class ServletEditScore extends HttpServlet{private Score score;private ServletFindAllScore servletFindAllScore=new ServletFindAllScore();private ScoreServiceImpl scoreServiceImpl=new ScoreServiceImpl();public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {int scoreID = Integer.parseInt(request.getParameter("scoreID"));String stuNum = request.getParameter("stuNum");String stuName = request.getParameter("stuName");String stuClass = request.getParameter("stuClass");String courseName = request.getParameter("courseName");double scoreGrade=Double.parseDouble(request.getParameter("scoreGrade"));String major = request.getParameter("major");score=new Score(scoreID,stuNum,stuName,stuClass,courseName,scoreGrade,major);int rs=scoreServiceImpl.editCos(score);if(rs>0){request.setAttribute("msg", "修改成功!!");servletFindAllScore.doGet(request, response);//request.getRequestDispatcher("admin/addCourse.jsp").forward(request, response);}else{request.setAttribute("msg", "修改失败!!");request.getRequestDispatcher("admin/editScore.jsp").forward(request, response);}
String major = request.getParameter("major");String department = request.getParameter("department");String phone = request.getParameter("phone");int roleID = Integer.parseInt(request.getParameter("role"));user = new User(stuNum, stuName, pwd, phone, roleID);student = new Student(stuNum, stuName, stuSex, stuAge, stuClass, major,department);int rsUser=userServiceImpl.addUser(user);int rsStu=studentServiceImpl.addStu(student);if(rsStu>0 && rsUser>0){request.setAttribute("massage", "注册成功!!");request.getRequestDispatcher("login/login.jsp").forward(request, response);}else{request.setAttribute("msg", "注册失败!!");request.getRequestDispatcher("register/register.jsp").forward(request, response);}}}public class ServletaddScore extends HttpServlet{private Score score;private ServletFindAllScore servletFindAllScore=new ServletFindAllScore();private ScoreServiceImpl scoreServiceImpl=new ScoreServiceImpl();public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {String stuNum = request.getParameter("stuNum");String stuName = request.getParameter("stuName");String stuClass = request.getParameter("stuClass");String courseName = request.getParameter("courseName");double scoreGrade=Double.parseDouble(request.getParameter("scoreGrade"));
}}else{/** * 处理文件名,上传后的文件是以uuid_文件名的形式去重新命名的,去除文件名的uuid_部分file.getName().indexOf("_")检索字符串中第一次出现"_"字符的位置,如果文件名类似于:9349249849-88343-8344_阿_凡_达.avi那么file.getName().substring(file.getName().indexOf("_")+1)处理之后就可以得到阿_凡_达.avi部分 */String realName=file.getName().substring(file.getName().indexOf("_")+1); //file.getName()得到的是文件的原始名称,这个名称是唯一的,因此可以作为key,realName是处理过后的名称,有可能会重复fileNameMap.put(file.getName(), realName);}}}public class ServletaddCourse extends HttpServlet{private Course course;private ServletFindAllCos servletFindAllCos=new ServletFindAllCos();private CourseServiceImpl courseServiceImpl=new CourseServiceImpl();public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {String courseName = request.getParameter("courseName");
// item.delete();message = "文件上传成功!";}}} catch (FileUploadBase.FileSizeLimitExceededException e) {e.printStackTrace();request.setAttribute("message", "单个文件超出最大值!!!");request.getRequestDispatcher("admin/fileLoadFail.jsp").forward(request, response);return;// e.printStackTrace();} catch (FileUploadBase.SizeLimitExceededException e) {e.printStackTrace();request.setAttribute("message", "上传文件的总的大小超出限制的最大值!!!");request.getRequestDispatcher("admin/fileLoadFail.jsp").forward(request, response);return;} catch (Exception e) {message = "文件上传失败!";e.printStackTrace();}request.setAttribute("message", message);request.getRequestDispatcher("admin/fileLoadFail.jsp").forward(request, response);}private String makePath(String saveFileName, String savePath) {// 得到文件名的hashCode的值,得到的就是fileName这个字符串对象在内存中的地址int hashCode = saveFileName.hashCode();int dir1 = hashCode & 0xf; // 0-15int dir2 = (hashCode & 0xf0) >> 4; // 0-15// 构造信息的保存目录String dir = savePath + "\\" + dir1 + "\\" + dir2;// file既可以代表文件也可以代表目录File file = new File(dir);// 如果目录不存在if (!file.exists()) {// 创建目录file.mkdirs();}return dir;}
private ScoreServiceImpl scoreServiceImpl=new ScoreServiceImpl();@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {req.setCharacterEncoding("utf-8");resp.setContentType("text/html;charset=utf-8");doPost(req, resp);}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {int pageNo=1;int pageCount=1;String pageNoStr=request.getParameter("pageNo");String pageCountStr=request.getParameter("pageCount");if(pageNoStr!=null){pageNo=Integer.parseInt(pageNoStr);}if(pageCountStr!=null){pageCount=Integer.parseInt(pageCountStr);}String stuNum=request.getParameter("stuNum");String courseName=request.getParameter("cosName");String stuName=request.getParameter("stuName");String stuClass=request.getParameter("stuClass");String major=request.getParameter("major");/*if(stuNum==""){stuNum=null;}if(courseName==""){courseName=null;}if(stuName==""){stuName=null;}if(stuClass==""){stuClass=null;}if(major==""){
String dir = savePath + "\\" + dir1 + "\\" + dir2;// file既可以代表文件也可以代表目录File file = new File(dir);// 如果目录不存在if (!file.exists()) {// 创建目录file.mkdirs();}return dir;}private String makeFileName(String fileName) {// 为防止文件覆盖的现象发生,要为上传文件产生一个唯一的文件名return UUID.randomUUID().toString() + "_" + fileName;}}public class ServletDownloadFile extends HttpServlet{@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {doPost(req, resp);}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {/*request.setCharacterEncoding("utf-8");response.setContentType("text/html;charset=utf-8");*/
private ScoreServiceImpl scoreServiceImpl=new ScoreServiceImpl();public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {int scoreID = Integer.parseInt(request.getParameter("scoreID"));String stuNum = request.getParameter("stuNum");String stuName = request.getParameter("stuName");String stuClass = request.getParameter("stuClass");String courseName = request.getParameter("courseName");double scoreGrade=Double.parseDouble(request.getParameter("scoreGrade"));String major = request.getParameter("major");score=new Score(scoreID,stuNum,stuName,stuClass,courseName,scoreGrade,major);int rs=scoreServiceImpl.editCos(score);if(rs>0){request.setAttribute("msg", "修改成功!!");servletFindAllScore.doGet(request, response);//request.getRequestDispatcher("admin/addCourse.jsp").forward(request, response);}else{request.setAttribute("msg", "修改失败!!");request.getRequestDispatcher("admin/editScore.jsp").forward(request, response);}}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doGet(request, response);}}