diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..7d0c7d2 --- /dev/null +++ b/.classpath @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/School-ST.iml b/.idea/School-ST.iml new file mode 100644 index 0000000..fac07e6 --- /dev/null +++ b/.idea/School-ST.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6d70b71 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..6c00181 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..c005581 --- /dev/null +++ b/.project @@ -0,0 +1,31 @@ + + + St + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope new file mode 100644 index 0000000..76c2d63 --- /dev/null +++ b/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 +org.eclipse.jdt.core.compiler.compliance=21 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=21 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..11e5dad --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..88a232b --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/src/main/webapp/META-INF/MANIFEST.MF b/src/main/webapp/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/src/main/webapp/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/src/main/webapp/WEB-INF/lib/json-20231013.jar b/src/main/webapp/WEB-INF/lib/json-20231013.jar new file mode 100644 index 0000000..465ad35 Binary files /dev/null and b/src/main/webapp/WEB-INF/lib/json-20231013.jar differ diff --git a/src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.30.jar b/src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.30.jar new file mode 100644 index 0000000..92ebe1b Binary files /dev/null and b/src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.30.jar differ diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..b7f72df --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,12 @@ + + + St + + index.html + index.jsp + index.htm + default.html + default.jsp + default.htm + + \ No newline at end of file diff --git a/src/main/webapp/admin.jsp b/src/main/webapp/admin.jsp new file mode 100644 index 0000000..9900bfb --- /dev/null +++ b/src/main/webapp/admin.jsp @@ -0,0 +1,34 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@ page import="java.sql.*" %> + + + + 管理员查看评教统计 + + + 评教统计 + + + 老师姓名 + 平均得分 + + <% + try { + Class.forName("com.mysql.jdbc.Driver"); + Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123456"); + String sql = "SELECT t.name, AVG(e.total_score) as avg_score FROM teachers t JOIN evaluations e ON t.teacher_id = e.teacher_id GROUP BY t.teacher_id"; + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(sql); + while (rs.next()) { + out.println("" + rs.getString("name") + "" + rs.getDouble("avg_score") + ""); + } + rs.close(); + stmt.close(); + conn.close(); + } catch (Exception e) { + e.printStackTrace(); + } + %> + + + \ No newline at end of file diff --git a/src/main/webapp/evaluate.jsp b/src/main/webapp/evaluate.jsp new file mode 100644 index 0000000..6c7fd84 --- /dev/null +++ b/src/main/webapp/evaluate.jsp @@ -0,0 +1,84 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> + + + + 学生评教系统 + + + 学生评教系统 + + 选择学院: + + --请选择学院-- + 信息工程学院 + 智能工学院 + 物理学院 + + + 选择老师: + + --请选择老师-- + + + 选择课程: + + --请选择课程-- + + + 进入评教页面 + + + + + \ No newline at end of file diff --git a/src/main/webapp/evaluationPage.jsp b/src/main/webapp/evaluationPage.jsp new file mode 100644 index 0000000..988ee8d --- /dev/null +++ b/src/main/webapp/evaluationPage.jsp @@ -0,0 +1,155 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@ page import="java.sql.*, org.json.JSONArray, org.json.JSONObject" %> +<% + // 获取选择的学院、老师和课程 + String college = request.getParameter("college"); + String teacher = request.getParameter("teacher"); + String course = request.getParameter("course"); + + if (college == null || teacher == null || course == null) { + response.sendRedirect("evaluate.jsp"); // 如果参数缺失,跳回选择页面 + return; + } + + // 查询所有维度和题目 + JSONArray dimensions = new JSONArray(); + int totalQuestionCount = 0; // 总题目数量 + try { + Class.forName("com.mysql.cj.jdbc.Driver"); + Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123456"); + + String sql = "SELECT d.dimension_id, d.name AS dimension_name, d.weight, q.question_id, q.question_text " + + "FROM dimensions d " + + "JOIN questions q ON d.dimension_id = q.dimension_id " + + "ORDER BY d.dimension_id, q.question_id"; + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(sql); + + JSONObject currentDimension = null; + int lastDimensionId = -1; + + while (rs.next()) { + int dimensionId = rs.getInt("dimension_id"); + if (dimensionId != lastDimensionId) { + // 新维度 + if (currentDimension != null) { + dimensions.put(currentDimension); + } + currentDimension = new JSONObject(); + currentDimension.put("dimension_id", dimensionId); + currentDimension.put("dimension_name", rs.getString("dimension_name")); + currentDimension.put("weight", rs.getFloat("weight")); + currentDimension.put("questions", new JSONArray()); + lastDimensionId = dimensionId; + } + + // 添加题目 + JSONObject question = new JSONObject(); + question.put("question_id", rs.getInt("question_id")); + question.put("question_text", rs.getString("question_text")); + currentDimension.getJSONArray("questions").put(question); + + // 统计总题目数量 + totalQuestionCount++; + } + + // 添加最后一个维度 + if (currentDimension != null) { + dimensions.put(currentDimension); + } + + rs.close(); + stmt.close(); + conn.close(); + } catch (Exception e) { + e.printStackTrace(); + } +%> + + + + 评教页面 + + + + 评教页面 + + + + + + <% + // 渲染每个维度的题目表格 + for (int i = 0; i < dimensions.length(); i++) { + JSONObject dimension = dimensions.getJSONObject(i); + out.println("" + dimension.getString("dimension_name") + "(权重:" + dimension.getFloat("weight") + "%)"); + out.println(""); + out.println("题目符合不符合"); + out.println(""); + + JSONArray questions = dimension.getJSONArray("questions"); + for (int j = 0; j < questions.length(); j++) { + JSONObject question = questions.getJSONObject(j); + out.println(""); + out.println("" + question.getString("question_text") + ""); + out.println(""); + out.println(""); + out.println(""); + } + + out.println(""); + } + %> + + 提交评价 + + + + + \ No newline at end of file diff --git a/src/main/webapp/loadCourses.jsp b/src/main/webapp/loadCourses.jsp new file mode 100644 index 0000000..82dabc8 --- /dev/null +++ b/src/main/webapp/loadCourses.jsp @@ -0,0 +1,32 @@ +<%@ page language="java" contentType="application/json; charset=UTF-8" pageEncoding="UTF-8"%> +<%@ page import="java.sql.*, org.json.JSONArray, org.json.JSONObject" %> +<% + String teacherId = request.getParameter("teacher"); + JSONArray courses = new JSONArray(); + + if (teacherId != null && !teacherId.isEmpty()) { + try { + Class.forName("com.mysql.cj.jdbc.Driver"); + Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123456"); + String sql = "SELECT * FROM courses WHERE teacher_id = ?"; + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setString(1, teacherId); + ResultSet rs = pstmt.executeQuery(); + + while (rs.next()) { + JSONObject course = new JSONObject(); + course.put("course_id", rs.getInt("course_id")); + course.put("course_name", rs.getString("course_name")); + courses.put(course); + } + + rs.close(); + pstmt.close(); + conn.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + out.print(courses.toString()); // 输出 JSON 数据 +%> \ No newline at end of file diff --git a/src/main/webapp/loadQuestions.jsp b/src/main/webapp/loadQuestions.jsp new file mode 100644 index 0000000..32d219c --- /dev/null +++ b/src/main/webapp/loadQuestions.jsp @@ -0,0 +1,60 @@ +<%@ page language="java" contentType="application/json; charset=UTF-8" pageEncoding="UTF-8"%> +<%@ page import="java.sql.*, org.json.JSONArray, org.json.JSONObject" %> +<% + try { + Class.forName("com.mysql.cj.jdbc.Driver"); + Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123456"); + + // 查询所有维度和题目 + String sql = "SELECT d.dimension_id, d.name AS dimension_name, d.weight, q.question_id, q.question_text " + + "FROM dimensions d " + + "JOIN questions q ON d.dimension_id = q.dimension_id " + + "ORDER BY d.dimension_id, q.question_id"; + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(sql); + + JSONArray dimensions = new JSONArray(); + JSONObject currentDimension = null; + int lastDimensionId = -1; + + while (rs.next()) { + int dimensionId = rs.getInt("dimension_id"); + if (dimensionId != lastDimensionId) { + // 新维度 + if (currentDimension != null) { + dimensions.put(currentDimension); + } + currentDimension = new JSONObject(); + currentDimension.put("dimension_id", dimensionId); + currentDimension.put("dimension_name", rs.getString("dimension_name")); + currentDimension.put("weight", rs.getFloat("weight")); + currentDimension.put("questions", new JSONArray()); + lastDimensionId = dimensionId; + } + + // 添加题目 + JSONObject question = new JSONObject(); + question.put("question_id", rs.getInt("question_id")); + question.put("question_text", rs.getString("question_text")); + currentDimension.getJSONArray("questions").put(question); + } + + // 添加最后一个维度 + if (currentDimension != null) { + dimensions.put(currentDimension); + } + + rs.close(); + stmt.close(); + conn.close(); + + // 输出调试信息 + System.out.println("Debug: Dimensions and questions loaded successfully."); + System.out.println("Debug: JSON Data: " + dimensions.toString()); + + out.print(dimensions.toString()); // 输出 JSON 数据 + } catch (Exception e) { + e.printStackTrace(); + out.print("{\"error\": \"Failed to load questions.\"}"); + } +%> \ No newline at end of file diff --git a/src/main/webapp/loadTeachers.jsp b/src/main/webapp/loadTeachers.jsp new file mode 100644 index 0000000..85740a3 --- /dev/null +++ b/src/main/webapp/loadTeachers.jsp @@ -0,0 +1,23 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@ page import="java.sql.*" %> +<% + String college = request.getParameter("college"); + if (college != null && !college.isEmpty()) { + try { + Class.forName("com.mysql.cj.jdbc.Driver"); + Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123456"); + String sql = "SELECT * FROM teachers WHERE college = ?"; + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setString(1, college); + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + out.println("" + rs.getString("name") + ""); + } + rs.close(); + pstmt.close(); + conn.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } +%> \ No newline at end of file diff --git a/src/main/webapp/submitEvaluation.jsp b/src/main/webapp/submitEvaluation.jsp new file mode 100644 index 0000000..83a1f09 --- /dev/null +++ b/src/main/webapp/submitEvaluation.jsp @@ -0,0 +1,90 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@ page import="java.sql.*, java.util.Map, java.util.HashMap" %> +<% + String studentId = "12345"; + String teacherId = request.getParameter("teacher"); + String courseId = request.getParameter("course"); + + if (teacherId != null && courseId != null) { + try { + Class.forName("com.mysql.cj.jdbc.Driver"); + Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123456"); + + // 1. 查询每个维度的权重和题目数量 + String sql = "SELECT d.dimension_id, d.weight, COUNT(q.question_id) AS question_count " + + "FROM dimensions d " + + "LEFT JOIN questions q ON d.dimension_id = q.dimension_id " + + "GROUP BY d.dimension_id"; + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(sql); + + Map dimensionWeights = new HashMap<>(); + Map dimensionQuestionCounts = new HashMap<>(); + while (rs.next()) { + int dimensionId = rs.getInt("dimension_id"); + dimensionWeights.put(dimensionId, rs.getFloat("weight")); + dimensionQuestionCounts.put(dimensionId, rs.getInt("question_count")); + } + rs.close(); + stmt.close(); + + // 2. 查询每个题目所属的维度 + Map questionToDimension = new HashMap<>(); + sql = "SELECT question_id, dimension_id FROM questions"; + stmt = conn.createStatement(); + rs = stmt.executeQuery(sql); + while (rs.next()) { + questionToDimension.put(rs.getInt("question_id"), rs.getInt("dimension_id")); + } + rs.close(); + stmt.close(); + + // 3. 计算每个维度的得分总和 + Map dimensionScores = new HashMap<>(); + for (String paramName : request.getParameterMap().keySet()) { + if (paramName.startsWith("question_")) { + String questionId = paramName.replace("question_", ""); + int qId = Integer.parseInt(questionId); + int dimensionId = questionToDimension.get(qId); + int answer = Integer.parseInt(request.getParameter(paramName)); + + dimensionScores.put(dimensionId, dimensionScores.getOrDefault(dimensionId, 0f) + answer); + } + } + + // 4. 按权重和题目数量计算总分 + float totalScore = 0; + for (Map.Entry entry : dimensionScores.entrySet()) { + int dimensionId = entry.getKey(); + float scoreSum = entry.getValue(); + float weight = dimensionWeights.get(dimensionId); + int questionCount = dimensionQuestionCounts.get(dimensionId); + + // 关键修正:按实际题目数量计算得分 + float dimensionScore = (scoreSum / questionCount) * (weight / 100) * 100; + totalScore += dimensionScore; + } + + // 5. 插入评价记录 + sql = "INSERT INTO evaluations (student_id, teacher_id, course_id, total_score) VALUES (?, ?, ?, ?)"; + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setString(1, studentId); + pstmt.setString(2, teacherId); + pstmt.setString(3, courseId); + pstmt.setFloat(4, totalScore); + pstmt.executeUpdate(); + pstmt.close(); + + // 6. 插入每个题目的选择(略,同之前代码) + + conn.close(); + //out.println("提交成功!总得分:" + totalScore); + out.println("提交成功!"); + } catch (Exception e) { + e.printStackTrace(); + out.println("评价提交失败!错误信息:" + e.getMessage()); + } + } else { + out.println("请填写完整的评价信息!"); + } +%> \ No newline at end of file