基本框架构建完成,上载文件

This commit is contained in:
sishenjieshuo 2025-02-10 12:47:58 +08:00
parent 621e3a2d00
commit c14dc33a21
25 changed files with 629 additions and 0 deletions

13
.classpath Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

21
.idea/School-ST.iml Normal file
View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="web" name="Web">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
</webroots>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="23" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/School-ST.iml" filepath="$PROJECT_DIR$/.idea/School-ST.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

31
.project Normal file
View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>St</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>

12
.settings/.jsdtscope Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**/node_modules/*|**/*.min.js|**/bower_components/*" kind="src" path="src/main/webapp"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

View File

@ -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

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="St">
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<property name="context-root" value="St"/>
<property name="java-output-path" value="/St/build/classes"/>
</wb-module>
</project-modules>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<runtime name="Apache Tomcat v9.0"/>
<fixed facet="wst.jsdt.web"/>
<fixed facet="jst.web"/>
<fixed facet="java"/>
<installed facet="java" version="21"/>
<installed facet="jst.web" version="4.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>

View File

@ -0,0 +1 @@
org.eclipse.wst.jsdt.launching.baseBrowserLibrary

View File

@ -0,0 +1 @@
Window

View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Class-Path:

Binary file not shown.

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>St</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>default.htm</welcome-file>
</welcome-file-list>
</web-app>

34
src/main/webapp/admin.jsp Normal file
View File

@ -0,0 +1,34 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<title>管理员查看评教统计</title>
</head>
<body>
<h1>评教统计</h1>
<table border="1">
<tr>
<th>老师姓名</th>
<th>平均得分</th>
</tr>
<%
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("<tr><td>" + rs.getString("name") + "</td><td>" + rs.getDouble("avg_score") + "</td></tr>");
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
%>
</table>
</body>
</html>

View File

@ -0,0 +1,84 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>学生评教系统</title>
</head>
<body>
<h1>学生评教系统</h1>
<form id="evaluationForm" action="evaluationPage.jsp" method="get">
<label for="college">选择学院:</label>
<select id="college" name="college" onchange="loadTeachers()">
<option value="">--请选择学院--</option>
<option value="信息工程学院">信息工程学院</option>
<option value="智能工学院">智能工学院</option>
<option value="物理学院">物理学院</option>
</select>
<label for="teacher">选择老师:</label>
<select id="teacher" name="teacher" onchange="loadCourses()">
<option value="">--请选择老师--</option>
</select>
<label for="course">选择课程:</label>
<select id="course" name="course">
<option value="">--请选择课程--</option>
</select>
<button type="submit">进入评教页面</button>
</form>
<script>
function loadTeachers() {
var college = document.getElementById("college").value;
if (college) {
var xhr = new XMLHttpRequest();
xhr.open("GET", "loadTeachers.jsp?college=" + college, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
document.getElementById("teacher").innerHTML = xhr.responseText;
}
};
xhr.send();
}
}
function loadCourses() {
var teacher = document.getElementById("teacher").value;
if (teacher) {
var xhr = new XMLHttpRequest();
xhr.open("GET", "loadCourses.jsp?teacher=" + teacher, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log("Debug: Response from loadCourses.jsp: " + xhr.responseText); // 调试信息
try {
var courses = JSON.parse(xhr.responseText);
var courseSelect = document.getElementById("course");
courseSelect.innerHTML = ""; // 清空课程选项
// 添加默认选项
var defaultOption = document.createElement("option");
defaultOption.value = "";
defaultOption.text = "--请选择课程--";
courseSelect.appendChild(defaultOption);
// 添加课程选项
courses.forEach(function(course) {
var option = document.createElement("option");
option.value = course.course_id;
option.text = course.course_name;
courseSelect.appendChild(option);
});
} catch (e) {
console.error("Debug: Error parsing JSON data: " + e.message); // 调试信息
}
} else {
console.error("Debug: AJAX request failed with status: " + xhr.status); // 调试信息
}
};
xhr.send();
}
}
</script>
</body>
</html>

View File

@ -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();
}
%>
<!DOCTYPE html>
<html>
<head>
<title>评教页面</title>
<style>
/* 表格样式 */
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
th, td {
padding: 10px;
border: 1px solid #ddd;
text-align: left;
}
th {
background-color: #f2f2f2;
}
.dimension-title {
font-size: 18px;
font-weight: bold;
margin-top: 20px;
margin-bottom: 10px;
}
.question-text {
font-weight: normal;
}
</style>
</head>
<body>
<h1>评教页面</h1>
<form action="submitEvaluation.jsp" method="post" onsubmit="return validateForm()" >
<input type="hidden" name="college" value="<%= college %>">
<input type="hidden" name="teacher" value="<%= teacher %>">
<input type="hidden" name="course" value="<%= course %>">
<%
// 渲染每个维度的题目表格
for (int i = 0; i < dimensions.length(); i++) {
JSONObject dimension = dimensions.getJSONObject(i);
out.println("<div class='dimension-title'>" + dimension.getString("dimension_name") + "(权重:" + dimension.getFloat("weight") + "%</div>");
out.println("<table>");
out.println("<thead><tr><th>题目</th><th>符合</th><th>不符合</th></tr></thead>");
out.println("<tbody>");
JSONArray questions = dimension.getJSONArray("questions");
for (int j = 0; j < questions.length(); j++) {
JSONObject question = questions.getJSONObject(j);
out.println("<tr>");
out.println("<td class='question-text'>" + question.getString("question_text") + "</td>");
out.println("<td><input type='radio' name='question_" + question.getInt("question_id") + "' value='1' required></td>");
out.println("<td><input type='radio' name='question_" + question.getInt("question_id") + "' value='0' required></td>");
out.println("</tr>");
}
out.println("</tbody></table>");
}
%>
<button type="submit">提交评价</button>
</form>
<script>
// 总题目数量(从后端传递)
const totalQuestionCount = <%= totalQuestionCount %>;
function validateForm() {
const allQuestions = document.querySelectorAll("input[type='radio']");
const answered = new Set();
// 检查每个题目的单选按钮是否被选中
allQuestions.forEach(input => {
if (input.checked) {
const questionId = input.name.replace("question_", "");
answered.add(questionId);
}
});
if (answered.size !== totalQuestionCount) {
alert("请完成所有题目的评价后再提交!");
return false;
}
return true;
}
</script>
</body>
</html>

View File

@ -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 数据
%>

View File

@ -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.\"}");
}
%>

View File

@ -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("<option value='" + rs.getInt("teacher_id") + "'>" + rs.getString("name") + "</option>");
}
rs.close();
pstmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
%>

View File

@ -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<Integer, Float> dimensionWeights = new HashMap<>();
Map<Integer, Integer> 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<Integer, Integer> 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<Integer, Float> 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<Integer, Float> 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("请填写完整的评价信息!");
}
%>