├── .gitignore ├── README.md ├── WebRoot ├── IMG │ ├── title.png │ ├── title2.png │ └── title3.png ├── JSP │ ├── Add.jsp │ ├── Add1.jsp │ ├── Add2.jsp │ ├── CountResult.jsp │ ├── Filter.jsp │ ├── FilterResult.jsp │ ├── Inquire.jsp │ └── InquireResult.jsp ├── META-INF │ └── MANIFEST.MF ├── WEB-INF │ └── web.xml └── index.jsp ├── src └── stuPackage │ ├── AddController1.java │ ├── AddProcess1.java │ ├── AddProcess2.java │ ├── CountProcess.java │ ├── DuplicateException.java │ ├── FilterProcess1.java │ ├── InquireProcess1.java │ ├── NotFoundException.java │ ├── Student.java │ └── StudentDA.java └── 运行界面截图 ├── 录入或修改结果(可在页面中修改成绩,点击提交保存).jpg ├── 录入或修改页面.jpg ├── 成绩筛选结果(按查询成绩降序排列).jpg ├── 成绩筛选页面.jpg ├── 成绩统计页面.jpg ├── 数据表内容.jpg ├── 数据表设计.jpg ├── 查询结果.jpg ├── 查询页面.jpg └── 系统首页.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | .metadata 2 | bin/ 3 | tmp/ 4 | *.tmp 5 | *.bak 6 | *.swp 7 | *~.nib 8 | local.properties 9 | .settings/ 10 | .loadpath 11 | 12 | # Eclipse Core 13 | .project 14 | 15 | # External tool builders 16 | .externalToolBuilders/ 17 | 18 | # Locally stored "Eclipse launch configurations" 19 | *.launch 20 | 21 | # PyDev specific (Python IDE for Eclipse) 22 | *.pydevproject 23 | 24 | # CDT-specific (C/C++ Development Tooling) 25 | .cproject 26 | 27 | # JDT-specific (Eclipse Java Development Tools) 28 | .classpath 29 | .myeclipse/ 30 | 31 | # Java annotation processor (APT) 32 | .factorypath 33 | 34 | # PDT-specific (PHP Development Tools) 35 | .buildpath 36 | 37 | # sbteclipse plugin 38 | .target 39 | 40 | # Tern plugin 41 | .tern-project 42 | 43 | # TeXlipse plugin 44 | .texlipse 45 | 46 | # STS (Spring Tool Suite) 47 | .springBeans 48 | 49 | # Code Recommenders 50 | .recommenders/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JavaWeb 2 | 用Java写的一个简单(渣渣)的基于Web学生成绩管理系统,使用access数据库,涉及到了java servlet和jsp的知识 3 | 其实是大二上面向对象的课设 -_- 4 | -------------------------------------------------------------------------------- /WebRoot/IMG/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d4smart/JavaWeb/6575a8ea85a18dff2c5a379361b4d24665fc64c6/WebRoot/IMG/title.png -------------------------------------------------------------------------------- /WebRoot/IMG/title2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d4smart/JavaWeb/6575a8ea85a18dff2c5a379361b4d24665fc64c6/WebRoot/IMG/title2.png -------------------------------------------------------------------------------- /WebRoot/IMG/title3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d4smart/JavaWeb/6575a8ea85a18dff2c5a379361b4d24665fc64c6/WebRoot/IMG/title3.png -------------------------------------------------------------------------------- /WebRoot/JSP/Add.jsp: -------------------------------------------------------------------------------- 1 | <%-- 录入或修改首页,选择方式和对应内容 --%> 2 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 录入 7 | 17 | 18 | 19 |
20 | 21 |
22 | 23 | 24 | 25 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
请选择筛选(录入或修改方式) 26 | 30 |
请输入课程或班级
41 |
42 |
43 | 44 | -------------------------------------------------------------------------------- /WebRoot/JSP/Add1.jsp: -------------------------------------------------------------------------------- 1 | <%-- 按班级录入页面 --%> 2 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 3 | <%@ page import="stuPackage.*" %> 4 | 5 | 6 | 7 | AddByClass 8 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | <% 27 | String way = (String)request.getAttribute("way"); 28 | String selectedClass = (String)request.getAttribute("selectedClass"); 29 | ArrayList students = (ArrayList)request.getAttribute("students"); 30 | session.setAttribute("num", String.valueOf(students.size())); 31 | session.setAttribute("classID", selectedClass); 32 | %> 33 |

您选中的班级是: <%=selectedClass %>

34 |

数据库中一共有<%=students.size() %> 个记录

35 |
36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | <% 46 | for (int i = 0; i < students.size(); i++) { 47 | Student student = students.get(i); 48 | %> 49 | 50 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | <%} %> 59 |
学号姓名MathPhysicsOopSport
60 | 61 |
62 |
63 | 64 | 65 | -------------------------------------------------------------------------------- /WebRoot/JSP/Add2.jsp: -------------------------------------------------------------------------------- 1 | <%-- 按课程录入页面 --%> 2 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 3 | <%@ page import="stuPackage.*" %> 4 | 5 | 6 | 7 | 按课程录入 8 | 22 | 23 | 24 | 25 |
26 | pic 27 | <% 28 | String way = (String)request.getAttribute("way"); 29 | String selectedCourse = (String)request.getAttribute("selectedCourse"); 30 | ArrayList students = (ArrayList)request.getAttribute("students"); 31 | session.setAttribute("num", String.valueOf(students.size())); 32 | session.setAttribute("course", selectedCourse); 33 | %> 34 |

您选择的课程是: <%=selectedCourse %>

35 |

数据库中共有 <%=students.size() %> 个记录

36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | <% 46 | for (int i = 0; i < students.size(); i++) { 47 | Student student = students.get(i); 48 | %> 49 | 50 | 52 | 53 | 54 | 55 | 56 | <%} %> 57 |
学号姓名班级<%= selectedCourse %>
58 | 59 |
60 |
61 |
62 | 63 | 64 | -------------------------------------------------------------------------------- /WebRoot/JSP/CountResult.jsp: -------------------------------------------------------------------------------- 1 | <%-- 统计结果显示页面 --%> 2 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 3 | 4 | <% String[] header = {"≥90","80~90","70~80","60~70","≤60"}; %> 5 | 6 | 7 | 8 | Count result 9 | 20 | 21 | 22 |
23 | pic 24 | 25 |

Database statistics (analysis by percent)

26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | <% 37 | for (int i = 0; i < 5; i++) { 38 | %> 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | <% } %> 47 | 48 |
Score MathPhysicsOopSport
<%=header[i] %><%=request.getAttribute("math"+(i+1)) %>%<%=request.getAttribute("physics"+(i+1)) %>%<%=request.getAttribute("oop"+(i+1)) %>%<%=request.getAttribute("sport"+(i+1)) %>%
49 | 50 | 51 | -------------------------------------------------------------------------------- /WebRoot/JSP/Filter.jsp: -------------------------------------------------------------------------------- 1 | <%-- 成绩筛选首页面 --%> 2 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | Filter page 7 | 19 | 20 | 21 |
22 | pic 23 |
24 | 25 | 26 | 27 | 35 | 36 | 37 | 38 | 47 | 48 |
筛选科目: 28 | 34 |
筛选条件: 39 | 46 |
49 |

50 |
51 | 52 | -------------------------------------------------------------------------------- /WebRoot/JSP/FilterResult.jsp: -------------------------------------------------------------------------------- 1 | <%-- 筛选结果显示页面 --%> 2 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 3 | <%@ page import="stuPackage.*" %> 4 | <% 5 | ArrayList students = (ArrayList)request.getAttribute("students"); 6 | String way = (String)request.getAttribute("way"); 7 | String subject = (String)request.getAttribute("subject"); 8 | %> 9 | 10 | 11 | 12 | Filter result 13 | 25 | 26 | 27 |
28 | pic 29 | <% if (way.equals("1")) {%> 30 |

There are <%=students.size() %> records who's <%=subject %> score ≥90

31 | <% } else if (way.equals("2")) { %> 32 |

There are <%=students.size() %> records who's <%=subject %> score between 80~90

33 | <% } else if (way.equals("3")) { %> 34 |

There are <%=students.size() %> records who's <%=subject %> score between 70~80

35 | <% } else if (way.equals("4")) { %> 36 |

There are <%=students.size() %> records who's <%=subject %> score between 60~70

37 | <% } else if (way.equals("5")) { %> 38 |

There are <%=students.size() %> records who's <%=subject %> score ≤60

39 | <% } %> 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | <% 53 | for (int i = 0; i < students.size(); i++) { 54 | Student student = students.get(i); 55 | %> 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | <%} %> 66 |
StudentIDNameClassMathPhysicsOopSport
<%= student.getStudentID()%><%= student.getName()%><%= student.getClassID()%><%= student.getMathScore()%><%= student.getPhysicsScore()%><%= student.getOopScore()%><%= student.getSportScore()%>
67 | 68 | 69 | -------------------------------------------------------------------------------- /WebRoot/JSP/Inquire.jsp: -------------------------------------------------------------------------------- 1 | <%-- 查询成绩页面,选择查询方式和对应的值 --%> 2 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | Inquire page 7 | 19 | 20 | 21 |
22 | pic 23 |
24 | 25 | 26 | 27 | 35 | 36 | 37 | 38 | 39 | 40 |
查询方式: 28 | 34 |
Selected value:
41 |

42 |
43 | 44 | -------------------------------------------------------------------------------- /WebRoot/JSP/InquireResult.jsp: -------------------------------------------------------------------------------- 1 | <%-- 查询结果页面 --%> 2 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 3 | <%@ page import="stuPackage.*" %> 4 | 5 | <% 6 | ArrayList students = (ArrayList)request.getAttribute("students"); 7 | String way = (String)request.getAttribute("way"); 8 | String value = (String)request.getAttribute("value"); 9 | %> 10 | 11 | 12 | 13 | Inquire result 14 | 26 | 27 | 28 |
29 | pic 30 | <% if (way.equals("1")) {%> 31 |

There are <%=students.size() %> records in class <%=value %>

32 | <% } else if (way.equals("2")) { %> 33 |

The record inquired by studentID

34 | <% } else if (way.equals("3")) { %> 35 |

Student found by name (maybe≥1)

36 | <% } else if (way.equals("4")) { %> 37 |

There are <%=students.size() %> records in the database totally

38 | <% } %> 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | <% 51 | for (int i = 0; i < students.size(); i++) { 52 | Student student = students.get(i); 53 | %> 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | <%} %> 64 |
StudentIDNameClassMathPhysicsOopSport
<%= student.getStudentID()%><%= student.getName()%><%= student.getClassID()%><%= student.getMathScore()%><%= student.getPhysicsScore()%><%= student.getOopScore()%><%= student.getSportScore()%>
65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /WebRoot/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /WebRoot/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | Judge the way and display jsp 8 | AddController1 9 | AddController1 10 | stuPackage.AddController1 11 | 12 | 13 | process data from class add/change 14 | AddProcess1 15 | AddProcess1 16 | stuPackage.AddProcess1 17 | 18 | 19 | process data from course add/change 20 | AddProcess2 21 | AddProcess2 22 | stuPackage.AddProcess2 23 | 24 | 25 | receive inquire choice and get data 26 | InquireProcess1 27 | InquireProcess1 28 | stuPackage.InquireProcess1 29 | 30 | 31 | receive filter condition and transmit data 32 | FilterProcess1 33 | FilterProcess1 34 | stuPackage.FilterProcess1 35 | 36 | 37 | count and analyse record 38 | CountProcess 39 | CountProcess 40 | stuPackage.CountProcess 41 | 42 | 43 | 44 | 45 | 46 | AddController1 47 | /AddController1 48 | 49 | 50 | AddProcess1 51 | /AddProcess1 52 | 53 | 54 | AddProcess2 55 | /AddProcess2 56 | 57 | 58 | InquireProcess1 59 | /InquireProcess1 60 | 61 | 62 | FilterProcess1 63 | /FilterProcess1 64 | 65 | 66 | CountProcess 67 | /CountProcess 68 | 69 | 70 | 71 | 72 | index.jsp 73 | 74 | 75 | -------------------------------------------------------------------------------- /WebRoot/index.jsp: -------------------------------------------------------------------------------- 1 | <%-- 学生信息管理系统首页 --%> 2 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 3 | 4 | 5 | 学生信息管理系统 6 | 29 | 30 | 31 |
32 | 33 |
34 | 35 | 36 | 37 | 38 | 39 | 40 |
41 |
42 |
43 | pic 44 |
45 |
46 | 47 | -------------------------------------------------------------------------------- /src/stuPackage/AddController1.java: -------------------------------------------------------------------------------- 1 | package stuPackage; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import javax.servlet.RequestDispatcher; 11 | 12 | public class AddController1 extends HttpServlet { 13 | 14 | public void service (HttpServletRequest req, HttpServletResponse res) 15 | throws ServletException,IOException { 16 | String way; 17 | String address = null; 18 | ArrayList students=new ArrayList (); 19 | 20 | // System.out.println(req.getServletPath()); 21 | 22 | // 获取jsp中选择的录入方式 23 | way = req.getParameter("selectedway"); 24 | 25 | // 根据不同的录入方式执行对应的操作 26 | if (way.equals("1")) { //按班级录入 27 | String selectedClass = req.getParameter("content"); 28 | 29 | // 找到指定班级的学生 30 | try { 31 | Student.initialize(); 32 | students = Student.find(selectedClass, "findClassID"); 33 | Student.terminate(); 34 | } catch (NotFoundException e) { 35 | System.out.println(e); 36 | } 37 | 38 | // 设置属性,jsp中可用对应方法获取 39 | req.setAttribute("way", way); 40 | req.setAttribute("selectedClass", selectedClass); 41 | req.setAttribute("students", students); 42 | 43 | // 对应跳转地址 44 | address = "./JSP/Add1.jsp"; 45 | // System.out.println(selectedClass+" "+way); 46 | } 47 | else if (way.equals("2")) { //按课程录入 48 | String selectedCourse = req.getParameter("content"); 49 | 50 | // 找到所有学生 51 | try { 52 | Student.initialize(); 53 | students = Student.find(selectedCourse, "all"); 54 | Student.terminate(); 55 | } catch (NotFoundException e) { 56 | System.out.println(e); 57 | } 58 | 59 | // 设置属性,jsp中可用对应方法获取 60 | req.setAttribute("way", way); 61 | req.setAttribute("selectedCourse", selectedCourse); 62 | req.setAttribute("students", students); 63 | 64 | address = "./JSP/Add2.jsp"; 65 | } 66 | 67 | RequestDispatcher dispatcher = req.getRequestDispatcher(address); 68 | dispatcher.forward(req, res); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/stuPackage/AddProcess1.java: -------------------------------------------------------------------------------- 1 | package stuPackage; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.ServletException; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import javax.servlet.RequestDispatcher; 10 | 11 | public class AddProcess1 extends HttpServlet { 12 | 13 | public void service (HttpServletRequest req, HttpServletResponse res) 14 | throws ServletException,IOException { 15 | // System.out.println("Start!"); 16 | int number = 0; 17 | String classID = (String)req.getSession().getAttribute("classID"); //获取选择的班级 18 | // System.out.println("classID: " + classID); 19 | 20 | 21 | 22 | try { 23 | String num = (String)req.getSession().getAttribute("num"); //获取学生数 24 | // System.out.println("Num: " + a); 25 | number = Integer.parseInt(num); 26 | } catch (NumberFormatException e) { 27 | System.out.println(e); 28 | } 29 | 30 | // System.out.println("Number is: "+number); 31 | 32 | Student.initialize(); 33 | for (int i = 0; i < number; i++) { 34 | // 转换成对应名称以获取jsp中的数据 35 | String id = "id" + i; 36 | String name1 = "name" + i; 37 | String math = "math" + i; 38 | String physics = "physics" + i; 39 | String oop = "oop" + i; 40 | String sport = "sport" + i; 41 | 42 | // 获取对应数据 43 | String studentID = req.getParameter(id); 44 | String name = req.getParameter(name1); 45 | int mathScore = Integer.parseInt(req.getParameter(math)); 46 | int physicsScore = Integer.parseInt(req.getParameter(physics)); 47 | int oopScore = Integer.parseInt(req.getParameter(oop)); 48 | int sportScore = Integer.parseInt(req.getParameter(sport)); 49 | 50 | // 创建对应实例 51 | Student student = new Student(studentID, name, classID, mathScore, physicsScore, oopScore, sportScore); 52 | 53 | // 写入数据库 54 | try { 55 | student.update(); 56 | } catch (NotFoundException e) { 57 | System.out.println(e); 58 | } 59 | } 60 | 61 | Student.terminate(); 62 | 63 | req.setAttribute("selectedway", "1"); 64 | req.setAttribute("content", classID); 65 | 66 | String address = "/JSP/Add.jsp"; 67 | RequestDispatcher dispatcher = req.getRequestDispatcher(address); 68 | dispatcher.forward(req, res); 69 | 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/stuPackage/AddProcess2.java: -------------------------------------------------------------------------------- 1 | package stuPackage; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import javax.servlet.RequestDispatcher; 11 | 12 | public class AddProcess2 extends HttpServlet { 13 | 14 | public void service (HttpServletRequest req, HttpServletResponse res) 15 | throws ServletException,IOException { 16 | int number = 0; 17 | String subject = (String) req.getSession().getAttribute("course"); //获取选择的课程 18 | 19 | try { 20 | number = Integer.parseInt((String)req.getSession().getAttribute("num")); //获取学生数 21 | } catch (NumberFormatException e) { 22 | System.out.println(e); 23 | } 24 | 25 | Student.initialize(); 26 | 27 | // 获取jsp的form表单中的数据并写入数据库 28 | for (int i = 0; i < number; i++) { 29 | // 转换成对应名称以匹配form表单中的name 30 | String id = "id" + i; 31 | String name1 = "name" + i; 32 | String classid = "class" + i; 33 | String course = subject + i; 34 | 35 | // 获取form表单中的数据 36 | String studentID = req.getParameter(id); 37 | String name = req.getParameter(name1); 38 | String classID = req.getParameter(classid); 39 | int courseScore = Integer.parseInt(req.getParameter(course)); 40 | 41 | Student student = null; 42 | 43 | // 创建对应Student实例 44 | try { 45 | student = Student.find(studentID); 46 | } catch (NotFoundException e1) { 47 | System.out.println(e1); 48 | } 49 | student.setName(name); 50 | student.setClassID(classID); 51 | student.setScore(subject, courseScore); 52 | 53 | // 写入修改后的数据 54 | try { 55 | student.update(); 56 | } catch (NotFoundException e) { 57 | System.out.println(e); 58 | } 59 | } 60 | Student.terminate(); 61 | 62 | req.setAttribute("selectedway", "2"); 63 | req.setAttribute("content", subject); 64 | 65 | String address = "/JSP/Add.jsp"; 66 | RequestDispatcher dispatcher = req.getRequestDispatcher(address); 67 | dispatcher.forward(req, res); 68 | 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/stuPackage/CountProcess.java: -------------------------------------------------------------------------------- 1 | package stuPackage; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.text.DecimalFormat; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import javax.servlet.RequestDispatcher; 12 | 13 | public class CountProcess extends HttpServlet { 14 | 15 | public void service (HttpServletRequest req, HttpServletResponse res) 16 | throws ServletException,IOException { 17 | // 要使用的变量 18 | ArrayList students = new ArrayList(); 19 | DecimalFormat df = new DecimalFormat("0.0"); //数据格式化类 20 | int a[] = { 90, 80, 70, 60, 0 }; //筛选对应下界 21 | int b[] = { 100, 90, 80, 70, 60 }; //筛选对应上界 22 | String sub[] = {"math","physics","oop","sport"}; //筛选对应科目 23 | 24 | Student.initialize(); 25 | int total = 0; 26 | try { 27 | total = Student.find("all", "all").size(); //数据库中学生总数 28 | } catch (NotFoundException e) { 29 | System.out.println(e); 30 | } 31 | // System.out.println(total); 32 | 33 | // 获取各分数段人数所占百分比并传给jsp(取一位小数,以String方式传输 如:12.5%->"12.5") 34 | for (int i = 0; i < 5; i++) { 35 | for (int j = 0; j < 4; j++) { 36 | 37 | try { 38 | students = Student.getspecific(a[i], b[i], sub[j]); 39 | } catch (NotFoundException e) { 40 | System.out.println(e); 41 | } 42 | 43 | double pecent = (double)students.size()/total * 100.0; 44 | String percent = df.format(pecent); 45 | req.setAttribute(sub[j]+(i+1), percent); 46 | // System.out.println(percent); 47 | 48 | } 49 | } 50 | 51 | Student.terminate(); 52 | 53 | // 跳转到对应jsp 54 | String address = "./JSP/CountResult.jsp"; 55 | 56 | RequestDispatcher dispatcher = req.getRequestDispatcher(address); 57 | dispatcher.forward(req, res); 58 | 59 | } 60 | } -------------------------------------------------------------------------------- /src/stuPackage/DuplicateException.java: -------------------------------------------------------------------------------- 1 | package stuPackage; 2 | 3 | // 重复异常 4 | public class DuplicateException extends Exception 5 | { 6 | public DuplicateException(String message) 7 | { 8 | super(message); 9 | } 10 | } -------------------------------------------------------------------------------- /src/stuPackage/FilterProcess1.java: -------------------------------------------------------------------------------- 1 | package stuPackage; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import javax.servlet.RequestDispatcher; 11 | 12 | public class FilterProcess1 extends HttpServlet { 13 | 14 | public void service (HttpServletRequest req, HttpServletResponse res) 15 | throws ServletException,IOException { 16 | // 要使用的变量 17 | String subject, way; 18 | String address; 19 | ArrayList students = new ArrayList(); 20 | 21 | // 获取用户选择的筛选科目和筛选方式 22 | subject = req.getParameter("filtersubject"); 23 | way = req.getParameter("filterway"); 24 | Student.initialize(); 25 | 26 | // 根据不同的筛选方式执行不同的数据库操作 27 | try { 28 | if (way.equals("1")) 29 | students = Student.getspecific(90, 100, subject); 30 | else if (way.equals("2")) 31 | students = Student.getspecific(80, 90, subject); 32 | else if (way.equals("3")) 33 | students = Student.getspecific(70, 80, subject); 34 | else if (way.equals("4")) 35 | students = Student.getspecific(60, 70, subject); 36 | else if (way.equals("5")) 37 | students = Student.getspecific(0, 60, subject); 38 | } catch (NotFoundException e) { 39 | System.out.println(e); 40 | } 41 | 42 | Student.terminate(); 43 | 44 | // 将ArrayList传给jsp 45 | req.setAttribute("students", students); 46 | req.setAttribute("way", way); 47 | req.setAttribute("subject", subject); 48 | 49 | address = "./JSP/FilterResult.jsp"; 50 | 51 | RequestDispatcher dispatcher = req.getRequestDispatcher(address); 52 | dispatcher.forward(req, res); 53 | 54 | } 55 | } -------------------------------------------------------------------------------- /src/stuPackage/InquireProcess1.java: -------------------------------------------------------------------------------- 1 | package stuPackage; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import javax.servlet.RequestDispatcher; 11 | 12 | public class InquireProcess1 extends HttpServlet { 13 | 14 | public void service (HttpServletRequest req, HttpServletResponse res) 15 | throws ServletException,IOException { 16 | // 要使用的变量 17 | String way,value; 18 | String address; 19 | ArrayList students = new ArrayList(); 20 | 21 | // 获取jsp中传来的数据(查询方式和对应的值) 22 | way = req.getParameter("inquireway"); 23 | value = req.getParameter("inquirevalue"); 24 | 25 | Student.initialize(); 26 | 27 | // 按不同的查询方式执行对应的数据库操作 28 | try { 29 | if (way.equals("1")) 30 | students = Student.find(value, "findClassID"); 31 | else if (way.equals("2")) { 32 | Student student = Student.find(value); 33 | students.add(student); 34 | } 35 | else if (way.equals("3")) 36 | students = Student.find(value, "findName"); 37 | else if (way.equals("4")) 38 | students = Student.find(value, "all"); 39 | 40 | } catch (NotFoundException e) { 41 | System.out.println(e); 42 | } 43 | 44 | Student.terminate(); 45 | 46 | // 将ArrayList传给jsp显示 47 | req.setAttribute("students", students); 48 | req.setAttribute("way", way); 49 | req.setAttribute("value", value); 50 | 51 | address = "./JSP/InquireResult.jsp"; 52 | 53 | RequestDispatcher dispatcher = req.getRequestDispatcher(address); 54 | dispatcher.forward(req, res); 55 | 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/stuPackage/NotFoundException.java: -------------------------------------------------------------------------------- 1 | package stuPackage; 2 | 3 | // 找不到数据异常 4 | public class NotFoundException extends Exception 5 | { 6 | public NotFoundException(String message) 7 | { 8 | super(message); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/stuPackage/Student.java: -------------------------------------------------------------------------------- 1 | package stuPackage; 2 | import java.util.*; 3 | public class Student 4 | { 5 | // Student的对象属性(信息+分数) 6 | private String studentID; 7 | private String name; 8 | private String classID; 9 | private int mathScore; 10 | private int physicsScore; 11 | private int oopScore; 12 | private int sportScore; 13 | 14 | // 构造方法 15 | public Student(String studentID,String name,String classID, 16 | int mathScore, int physicsScore, int oopScore, int sportScore) 17 | { 18 | setStudentID(studentID); 19 | setName(name); 20 | setClassID(classID); 21 | setMathScore(mathScore); 22 | setPhysicsScore(physicsScore); 23 | setOopScore(oopScore); 24 | setSportScore(sportScore); 25 | } 26 | 27 | // getters,setters方法 28 | public String getStudentID() { 29 | return studentID; 30 | } 31 | public void setStudentID(String studentID) { 32 | this.studentID = studentID; 33 | } 34 | public String getName() { 35 | return name; 36 | } 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | public String getClassID() { 41 | return classID; 42 | } 43 | public void setClassID(String classID) { 44 | this.classID = classID; 45 | } 46 | public int getMathScore() { 47 | return mathScore; 48 | } 49 | public void setMathScore(int mathScore) { 50 | this.mathScore = mathScore; 51 | } 52 | public int getPhysicsScore() { 53 | return physicsScore; 54 | } 55 | public void setPhysicsScore(int physicsScore) { 56 | this.physicsScore = physicsScore; 57 | } 58 | public int getOopScore() { 59 | return oopScore; 60 | } 61 | public void setOopScore(int oopScore) { 62 | this.oopScore = oopScore; 63 | } 64 | public int getSportScore() { 65 | return sportScore; 66 | } 67 | public void setSportScore(int sportScore) { 68 | this.sportScore = sportScore; 69 | } 70 | // 为获取和设置特定分数数据而设计的方法 71 | public int getScore(String subject) { 72 | if (subject.equals("Math")) 73 | return mathScore; 74 | else if (subject.equals("Physics")) 75 | return physicsScore; 76 | else if (subject.equals("Oop")) 77 | return oopScore; 78 | else if (subject.equals("Sport")) 79 | return sportScore; 80 | return 0; 81 | } 82 | public void setScore(String subject, int score) { 83 | if (subject.equals("Math")) 84 | setMathScore(score); 85 | else if (subject.equals("Physics")) 86 | setPhysicsScore(score); 87 | else if (subject.equals("Oop")) 88 | setOopScore(score); 89 | else if (subject.equals("Sport")) 90 | setSportScore(score); 91 | } 92 | 93 | // 获取学生信息 94 | public String getDetial() { 95 | String info = getStudentID()+" "+getName()+"\t"+getClassID()+" "+ 96 | getMathScore()+" "+getPhysicsScore()+" "+getOopScore()+ 97 | " "+getSportScore(); 98 | return info; 99 | } 100 | 101 | // 数据库静态方法 102 | public static void initialize() 103 | { 104 | StudentDA.initialize(); 105 | } 106 | public static void terminate() 107 | { 108 | StudentDA.terminate(); 109 | } 110 | public static Student find(String key) throws NotFoundException { 111 | return StudentDA.find(key); 112 | } 113 | public static ArrayList find(String key,String type) throws NotFoundException 114 | { 115 | return StudentDA.find(key,type); 116 | } 117 | 118 | // 数据库实例方法 119 | public void add() throws DuplicateException 120 | { 121 | StudentDA.add(this); 122 | } 123 | public void delete() throws NotFoundException 124 | { 125 | StudentDA.delete(this); 126 | } 127 | public void update() throws NotFoundException 128 | { 129 | StudentDA.update(this); 130 | } 131 | public static ArrayList getspecific(int botton,int top,String project) throws NotFoundException 132 | { 133 | return StudentDA.getspecific(botton,top,project); 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /src/stuPackage/StudentDA.java: -------------------------------------------------------------------------------- 1 | package stuPackage; 2 | import java.sql.*; 3 | import java.util.*; 4 | 5 | public class StudentDA 6 | { 7 | // Student实例 8 | static Student astudent; 9 | 10 | // 数据库连接使用的对象 11 | static String url="jdbc:odbc:StudentDB1"; 12 | static Connection aConnection; 13 | static Statement aStatement; 14 | 15 | // 用于暂存数据 16 | static String stuID; 17 | static String name; 18 | static String classID; 19 | static int mathScore; 20 | static int physicsScore; 21 | static int oopScore; 22 | static int sportScore; 23 | 24 | // 连接数据库 25 | public static Connection initialize() 26 | { 27 | try 28 | { 29 | // 加载程序 30 | Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 31 | 32 | // 创建连接 33 | aConnection=DriverManager.getConnection(url,"",""); 34 | aStatement=aConnection.createStatement(); 35 | } 36 | catch(ClassNotFoundException e) 37 | { 38 | System.out.println(e); 39 | } 40 | catch(SQLException e) 41 | { 42 | System.out.println(e); 43 | } 44 | return aConnection; 45 | } 46 | 47 | 48 | // 与数据库断开连接 49 | public static void terminate() 50 | { 51 | try 52 | { 53 | aStatement.close(); 54 | aConnection.close(); 55 | } 56 | catch(SQLException e) 57 | { 58 | System.out.println(e); 59 | } 60 | } 61 | 62 | // 通过StudentID(主键)查找学生记录,返回一个Student实例 63 | public static Student find(String key) throws NotFoundException { 64 | astudent = null; 65 | String sql = "SELECT studentID,name,classID,mathScore,physicsScore,oopScore,sportScore FROM UserT"+ 66 | " WHERE studentID='"+key+"'"; 67 | 68 | try { 69 | ResultSet rs=aStatement.executeQuery(sql); 70 | if(rs.next()) 71 | { 72 | // 获取属性 73 | stuID=rs.getString("studentID"); 74 | name=rs.getString("name"); 75 | classID=rs.getString("classID"); 76 | mathScore=rs.getInt("mathScore"); 77 | physicsScore=rs.getInt("physicsScore"); 78 | oopScore=rs.getInt("oopScore"); 79 | sportScore=rs.getInt("sportScore"); 80 | 81 | // 创建实例 82 | astudent=new Student(stuID,name,classID,mathScore,physicsScore,oopScore,sportScore); 83 | } 84 | } catch (SQLException e) { 85 | e.printStackTrace(); 86 | } 87 | 88 | return astudent; //返回 89 | } 90 | 91 | // find函数:在找不到相关记录时会返回一个异常 92 | // type为查找类型,有三种选择"findName","findClassID","all"分别对应3种查询方式 93 | // 返回的数据放在一个ArrayList里面 94 | public static ArrayList find(String key,String type) throws NotFoundException 95 | { 96 | astudent=null; 97 | ArrayList students=new ArrayList (); 98 | String sql=""; 99 | 100 | // 判断查找类型 101 | if(type.equals("findName")) 102 | { 103 | sql="SELECT studentID,name,classID,mathScore,physicsScore,oopScore,sportScore FROM UserT"+ 104 | " WHERE name='"+key+"'"+ 105 | " ORDER BY studentID"; 106 | } 107 | if(type.equals("findClassID")) 108 | { 109 | sql="SELECT studentID,name,classID,mathScore,physicsScore,oopScore,sportScore FROM UserT"+ 110 | " WHERE classID='"+key+"'"+ 111 | " ORDER BY studentID"; 112 | } 113 | if(type.equals("all")) 114 | { 115 | sql="SELECT studentID,name,classID,mathScore,physicsScore,oopScore,sportScore FROM UserT"+ 116 | " ORDER BY studentID"; 117 | } 118 | 119 | try 120 | { 121 | ResultSet rs=aStatement.executeQuery(sql); 122 | 123 | // 获取查找到的学生记录并添加到ArrayList中 124 | if(rs.next()) 125 | { 126 | stuID=rs.getString("studentID"); 127 | name=rs.getString("name"); 128 | classID=rs.getString("classID"); 129 | mathScore=rs.getInt("mathScore"); 130 | physicsScore=rs.getInt("physicsScore"); 131 | oopScore=rs.getInt("oopScore"); 132 | sportScore=rs.getInt("sportScore"); 133 | 134 | astudent=new Student(stuID,name,classID,mathScore,physicsScore,oopScore,sportScore); 135 | students.add(astudent); 136 | } 137 | else 138 | { 139 | throw(new NotFoundException("There is no such record!")); 140 | } 141 | while(rs.next()) 142 | { 143 | stuID=rs.getString("studentID"); 144 | name=rs.getString("name"); 145 | classID=rs.getString("classID"); 146 | mathScore=rs.getInt("mathScore"); 147 | physicsScore=rs.getInt("physicsScore"); 148 | oopScore=rs.getInt("oopScore"); 149 | sportScore=rs.getInt("sportScore"); 150 | 151 | astudent=new Student(stuID,name,classID,mathScore,physicsScore,oopScore,sportScore); 152 | students.add(astudent); 153 | } 154 | 155 | rs.close(); 156 | } 157 | catch(SQLException e) 158 | { 159 | System.out.println(e); 160 | } 161 | 162 | // 返回Arraylist 163 | return students; 164 | } 165 | 166 | 167 | // add函数:录入功能,当数据表中存在相关数据则返回一个异常 168 | public static void add(Student astudent) throws DuplicateException 169 | { 170 | Student student; 171 | 172 | // 获取学生属性 173 | stuID=astudent.getStudentID(); 174 | name=astudent.getName(); 175 | classID=astudent.getClassID(); 176 | mathScore=astudent.getMathScore(); 177 | physicsScore=astudent.getPhysicsScore(); 178 | oopScore=astudent.getOopScore(); 179 | sportScore=astudent.getSportScore(); 180 | 181 | String sql="INSERT INTO UserT (studentID,name,classID,mathScore,physicsScore,oopScore,sportScore) "+ 182 | "VALUES ('"+stuID+"','"+name+"','"+classID+"','"+mathScore+"','"+physicsScore+"','"+oopScore+"','" 183 | +sportScore+"')"; 184 | 185 | //System.out.println(sql); 186 | 187 | // 若数据库中已有此记录,返回异常;没有就录入数据库 188 | try 189 | { 190 | student=find(stuID); 191 | throw(new DuplicateException("This record is already exits!")); 192 | } 193 | catch(NotFoundException e) 194 | { 195 | try 196 | { 197 | int result=aStatement.executeUpdate(sql); 198 | } 199 | catch(SQLException ee) 200 | { 201 | System.out.println(ee); 202 | } 203 | } 204 | } 205 | 206 | 207 | // delete函数:删除功能,当找不到相关数据时会返回一个异常 208 | public static void delete(Student astudent) throws NotFoundException 209 | { 210 | stuID=astudent.getStudentID(); 211 | Student student; 212 | String sql="DELETE FROM UserT "+"WHERE studentID='"+stuID+"'"; 213 | 214 | // 查找有无此记录,没有就返回异常。若找到就执行删除操作 215 | try 216 | { 217 | try 218 | { 219 | student=find(stuID); 220 | int result=aStatement.executeUpdate(sql); 221 | } 222 | catch(NotFoundException e) 223 | { 224 | throw(new NotFoundException("Cannot Found the Record While deleting!")); 225 | } 226 | 227 | } 228 | catch(SQLException e) 229 | { 230 | System.out.println(e); 231 | } 232 | } 233 | 234 | 235 | // update函数:更新学生信息,当找不到相关记录时,会返回一个异常 236 | public static void update(Student astudent) throws NotFoundException 237 | { 238 | Student student; 239 | 240 | // 获取属性 241 | stuID=astudent.getStudentID(); 242 | name=astudent.getName(); 243 | classID=astudent.getClassID(); 244 | mathScore=astudent.getMathScore(); 245 | physicsScore=astudent.getPhysicsScore(); 246 | oopScore=astudent.getOopScore(); 247 | sportScore=astudent.getSportScore(); 248 | 249 | String sql="UPDATE UserT SET studentID='"+stuID+"',name='"+name+"',classID='"+classID+"',mathScore='"+mathScore 250 | +"',physicsScore='"+physicsScore+"',oopScore='"+oopScore+"',sportScore='"+sportScore 251 | +"' WHERE studentID='"+stuID+"'"; 252 | // System.out.println(sql); 253 | 254 | // 若找到学生记录就更新数据 255 | try 256 | { 257 | try 258 | { 259 | student=find(stuID); 260 | int result=aStatement.executeUpdate(sql); 261 | } 262 | catch(NotFoundException e) 263 | { 264 | throw (new NotFoundException("Cannot Found the Record while updating!")); 265 | } 266 | 267 | } 268 | catch(SQLException e) 269 | { 270 | System.out.println("\nupdate"+e); 271 | } 272 | } 273 | 274 | // 获取指定科目指定分数段的学生数据,以ArrayList返回,并从高到低排列 275 | // 挑选出 botton <= score < top 276 | // project可以传入“math”,“physics”,“oop”,“sport” 277 | public static ArrayList getspecific(int botton,int top,String project) throws NotFoundException 278 | { 279 | astudent=null; 280 | ArrayList students=new ArrayList (); 281 | String sql=""; 282 | 283 | // 判断科目,匹配对应的sql语句 284 | if(project.equals("math")) 285 | { 286 | sql="SELECT studentID,name,classID,mathScore,physicsScore,oopScore,sportScore FROM UserT"+ 287 | " WHERE mathScore>="+botton+" AND mathScore<"+top+ 288 | " ORDER BY mathScore DESC"; 289 | } 290 | if(project.equals("physics")) 291 | { 292 | sql="SELECT studentID,name,classID,mathScore,physicsScore,oopScore,sportScore FROM UserT"+ 293 | " WHERE physicsScore>="+botton+" AND physicsScore<"+top+ 294 | " ORDER BY physicsScore DESC"; 295 | } 296 | if(project.equals("oop")) 297 | { 298 | sql="SELECT studentID,name,classID,mathScore,physicsScore,oopScore,sportScore FROM UserT"+ 299 | " WHERE oopScore>="+botton+" AND oopScore<"+top+ 300 | " ORDER BY oopScore DESC"; 301 | } 302 | if(project.equals("sport")) 303 | { 304 | sql="SELECT studentID,name,classID,mathScore,physicsScore,oopScore,sportScore FROM UserT"+ 305 | " WHERE sportScore>="+botton+" AND sportScore<"+top+ 306 | " ORDER BY sportScore DESC"; 307 | } 308 | 309 | // 执行数据库操作并将结果放入ArrayList 310 | try 311 | { 312 | ResultSet rs=aStatement.executeQuery(sql); 313 | 314 | if(rs.next()) 315 | { 316 | stuID=rs.getString("studentID"); 317 | name=rs.getString("name"); 318 | classID=rs.getString("classID"); 319 | mathScore=rs.getInt("mathScore"); 320 | physicsScore=rs.getInt("physicsScore"); 321 | oopScore=rs.getInt("oopScore"); 322 | sportScore=rs.getInt("sportScore"); 323 | 324 | astudent=new Student(stuID,name,classID,mathScore,physicsScore,oopScore,sportScore); 325 | students.add(astudent); 326 | } 327 | else 328 | { 329 | throw(new NotFoundException("There is no such record!")); 330 | } 331 | 332 | while(rs.next()) 333 | { 334 | stuID=rs.getString("studentID"); 335 | name=rs.getString("name"); 336 | classID=rs.getString("classID"); 337 | mathScore=rs.getInt("mathScore"); 338 | physicsScore=rs.getInt("physicsScore"); 339 | oopScore=rs.getInt("oopScore"); 340 | sportScore=rs.getInt("sportScore"); 341 | 342 | astudent=new Student(stuID,name,classID,mathScore,physicsScore,oopScore,sportScore); 343 | students.add(astudent); 344 | } 345 | 346 | rs.close(); 347 | } 348 | catch(SQLException e) 349 | { 350 | System.out.println(e); 351 | } 352 | 353 | // 返回ArrayList 354 | return students; 355 | } 356 | } -------------------------------------------------------------------------------- /运行界面截图/录入或修改结果(可在页面中修改成绩,点击提交保存).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d4smart/JavaWeb/6575a8ea85a18dff2c5a379361b4d24665fc64c6/运行界面截图/录入或修改结果(可在页面中修改成绩,点击提交保存).jpg -------------------------------------------------------------------------------- /运行界面截图/录入或修改页面.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d4smart/JavaWeb/6575a8ea85a18dff2c5a379361b4d24665fc64c6/运行界面截图/录入或修改页面.jpg -------------------------------------------------------------------------------- /运行界面截图/成绩筛选结果(按查询成绩降序排列).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d4smart/JavaWeb/6575a8ea85a18dff2c5a379361b4d24665fc64c6/运行界面截图/成绩筛选结果(按查询成绩降序排列).jpg -------------------------------------------------------------------------------- /运行界面截图/成绩筛选页面.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d4smart/JavaWeb/6575a8ea85a18dff2c5a379361b4d24665fc64c6/运行界面截图/成绩筛选页面.jpg -------------------------------------------------------------------------------- /运行界面截图/成绩统计页面.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d4smart/JavaWeb/6575a8ea85a18dff2c5a379361b4d24665fc64c6/运行界面截图/成绩统计页面.jpg -------------------------------------------------------------------------------- /运行界面截图/数据表内容.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d4smart/JavaWeb/6575a8ea85a18dff2c5a379361b4d24665fc64c6/运行界面截图/数据表内容.jpg -------------------------------------------------------------------------------- /运行界面截图/数据表设计.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d4smart/JavaWeb/6575a8ea85a18dff2c5a379361b4d24665fc64c6/运行界面截图/数据表设计.jpg -------------------------------------------------------------------------------- /运行界面截图/查询结果.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d4smart/JavaWeb/6575a8ea85a18dff2c5a379361b4d24665fc64c6/运行界面截图/查询结果.jpg -------------------------------------------------------------------------------- /运行界面截图/查询页面.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d4smart/JavaWeb/6575a8ea85a18dff2c5a379361b4d24665fc64c6/运行界面截图/查询页面.jpg -------------------------------------------------------------------------------- /运行界面截图/系统首页.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d4smart/JavaWeb/6575a8ea85a18dff2c5a379361b4d24665fc64c6/运行界面截图/系统首页.jpg --------------------------------------------------------------------------------