赞
踩
基于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)
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{
return "SF"; } 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"); String phone = request.getParameter("phone"); int roleID = Integer.parseInt(request.getParameter("role")); user = new User(teaNum, teaName, pwd, phone, roleID); teacher = new Teacher(teaNum, teaName, teaSex, teaAge, teaCourse, major, department); //验证是否存在该教师 User rs=userServiceImpl.login(user);
@SuppressWarnings("serial") public class ServletUploadFile extends HttpServlet{ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 得到上传文件的保存目录,将上传的文件存放于服务器WEB-INF目录下,不允许外界直接访问,保证上传文件的安全性 String savePath = this.getServletContext().getRealPath( "/WEB-INF/upload"); // 上传时生成临时文件保存目录 String tempPath = this.getServletContext().getRealPath("/WEB-INF/temp"); File tempFile = new File(tempPath); if (!tempFile.exists()) { // 创建临时文件目录 tempFile.mkdir(); } // 消息提醒 String message = "";
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{ request.setAttribute("msg", "修改失败!!"); selectOne.doGet(request, response); //request.getRequestDispatcher("admin/editCourse.jsp").forward(request, response); } } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } } public class ServletRegistersStudent extends HttpServlet{ private User user; private Student student; private UserServiceImpl userServiceImpl = new UserServiceImpl(); private StudentServiceImpl studentServiceImpl =new StudentServiceImpl(); @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp);
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==""){ 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{
//System.out.println("上传文件扩展名是:" + fileExtName); // 获取item中的上传文件的输入流 InputStream is = item.getInputStream(); // 得到文件保存的名称 String saveFileName = makeFileName(fileName); // 得到文件保存目录 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", "上传文件的总的大小超出限制的最大值!!!");
double scoreGrade=Double.parseDouble(request.getParameter("scoreGrade")); String major = request.getParameter("major"); score=new Score(stuNum,stuName,stuClass,courseName,scoreGrade,major); Score scor=scoreServiceImpl.selectScoreInfo(score); if(scor==null){ int rs=scoreServiceImpl.addScore(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/addScore.jsp").forward(request, response); } }else{ request.setAttribute("msg", "该生的本门课成绩已录入,请重新录入!!"); request.getRequestDispatcher("admin/addScore.jsp").forward(request, response); } } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } } public class ServletSearchScore extends HttpServlet{ private Score score; private ScoreServiceImpl scoreServiceImpl=new ScoreServiceImpl(); @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); resp.setContentType("text/html;charset=utf-8");
request, response); } private String makePath(String saveFileName, String savePath) { // 得到文件名的hashCode的值,得到的就是fileName这个字符串对象在内存中的地址 int hashCode = saveFileName.hashCode(); int dir1 = hashCode & 0xf; // 0-15 int 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 String makeFileName(String fileName) { // 为防止文件覆盖的现象发生,要为上传文件产生一个唯一的文件名 return UUID.randomUUID().toString() + "_" + fileName; } } public class ServletDownloadFile extends HttpServlet{ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp)
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); } } public class ServletEditStu extends HttpServlet{ private Student student; 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 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"); student = new Student(stuNum, stuName, stuSex, stuAge, stuClass, major, department); int rs=studentServiceImpl.editStu(student); if(rs>0){ request.setAttribute("msg", "修改成功!!"); findStu.doGet(request, response); }else{ request.setAttribute("msg", "修改失败!!"); request.getRequestDispatcher("admin/editStudent.jsp").forward(request, response); }
}else{ request.setAttribute("massage","用户不存在!!"); request.getRequestDispatcher("login/login.jsp").forward(request, response); } } public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ doGet(request,response); } } 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);
String name = item.getFieldName(); /*// 解决普通输入项的数据中文乱码 String value = item.getString("utf-8"); System.out.println(name + "=" + value);*/ } else { // 吐过fileitem中封装的是上传文件 // 得到上传的文件名称 String fileName = item.getName(); if (fileName == null || fileName.trim().equals("")) { continue; } // 注意:不同的浏览器提交的文件名是不一样的,有些浏览器提交上来的文件名是带有路径的, // 如: c:\a\b\1.txt,而有些只是单纯的文件名,如:1.txt // 处理获取到的上传文件的文件名的路径部分,只保留文件名部分 fileName = fileName .substring(fileName.lastIndexOf("\\") + 1); // 得到上传文件扩展名 String fileExtName = fileName.substring(fileName .lastIndexOf(".") + 1); // 如果需要限制上传的文件类型,那么可以通过文件扩展名来判断文件类型是否合法 //System.out.println("上传文件扩展名是:" + fileExtName); // 获取item中的上传文件的输入流 InputStream is = item.getInputStream(); // 得到文件保存的名称 String saveFileName = makeFileName(fileName); // 得到文件保存目录 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(); // 删除处理文件上传时生成的临时文件
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"); String phone = request.getParameter("phone"); int roleID = Integer.parseInt(request.getParameter("role")); user = new User(teaNum, teaName, pwd, phone, roleID); teacher = new Teacher(teaNum, teaName, teaSex, teaAge, teaCourse, major, department); //验证是否存在该教师 User rs=userServiceImpl.login(user); if(rs.getUserID()==0){ int rsUser=userServiceImpl.addUser(user); int rsTea=teacherServiceImpl.addTea(teacher); if(rsTea>0 && rsUser>0){ request.setAttribute("msg", "添加成功!!"); findTea.doGet(request, response); // request.getRequestDispatcher("admin/teacherAllInfo.jsp").forward(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/addTeacher.jsp").forward(request, response); } }else{ request.setAttribute("msg", "该工号已存在,请重新录入!!"); request.getRequestDispatcher("admin/addTeacher.jsp").forward(request, response); }
public class ServletRegistersStudent extends HttpServlet{ private User user; private Student student; private UserServiceImpl userServiceImpl = new UserServiceImpl(); private StudentServiceImpl studentServiceImpl =new StudentServiceImpl(); @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } @Override protected 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){ request.setAttribute("massage", "注册成功!!"); request.getRequestDispatcher("login/login.jsp").forward(request, response); }else{ request.setAttribute("msg", "注册失败!!"); request.getRequestDispatcher("register/register.jsp").forward(request, response); }
if (UserAgent.indexOf("safari") >= 0) return "SF"; } 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");
@SuppressWarnings("serial") public class ServletUploadFile extends HttpServlet{ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 得到上传文件的保存目录,将上传的文件存放于服务器WEB-INF目录下,不允许外界直接访问,保证上传文件的安全性 String savePath = this.getServletContext().getRealPath( "/WEB-INF/upload"); // 上传时生成临时文件保存目录 String tempPath = this.getServletContext().getRealPath("/WEB-INF/temp"); File tempFile = new File(tempPath); if (!tempFile.exists()) { // 创建临时文件目录 tempFile.mkdir(); } // 消息提醒
public class ServletListFile extends HttpServlet{ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } @Override protected 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(); //遍历files数组 for(File f:files){
} } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } } public class ServletListFile extends HttpServlet{ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } @Override protected 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(); //遍历files数组
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); } } public class ServletTeaSearchScore extends HttpServlet{ private Score score; private ScoreServiceImpl scoreServiceImpl=new ScoreServiceImpl();
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。