老年人能力评估系统web端#6
完成了能力的统计,在查看界面显示能力等级

package com.xxx.web;
import com.xxx.pojo.User;
import com.xxx.service.DailyService;
import com.xxx.service.MentalService;
import com.xxx.service.SensoryService;
import com.xxx.service.SocialService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/gradeServlet")
public class GradeServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
DailyService dailyService = new DailyService();
MentalService mentalService = new MentalService();
SensoryService sensoryService = new SensoryService();
SocialService socialService = new SocialService();
HttpSession session = req.getSession();
User user = (User) session.getAttribute("user");
// 检查用户是否登录
if (user == null) {
resp.sendRedirect("login.jsp"); // 如果用户未登录,跳转到登录页面
return;
}
// 获取各项分级的值
Integer activityLevel = null;
Integer mentalStateLevel = null;
Integer sensoryCommunicationLevel = null;
Integer participationLevel = null;
try {
activityLevel = Integer.parseInt(dailyService.select(user.getId()).getActivity_level());
mentalStateLevel = Integer.parseInt(mentalService.select(user.getId()).getMental_state_level());
sensoryCommunicationLevel = Integer.parseInt(sensoryService.getSensory(user.getId()).getSensory_communication_level());
participationLevel = Integer.parseInt(socialService.getSocialById(user.getId()).getParticipation_level());
} catch (NumberFormatException | NullPointerException e) {
// 如果某个值为空或无法解析为整数,设置错误消息并跳转到提示页面
req.setAttribute("errorMessage", "请完成表格填写");
req.getRequestDispatcher("menu.jsp").forward(req, resp);
return;
}
req.setAttribute("activityLevel", activityLevel);
req.setAttribute("mentalStateLevel", mentalStateLevel);
req.setAttribute("sensoryCommunicationLevel", sensoryCommunicationLevel);
req.setAttribute("participationLevel", participationLevel);
// 定义初步等级
String initialLevel = "";
// 判断初步等级
if (activityLevel == 0 && mentalStateLevel == 0 && sensoryCommunicationLevel == 0 && (participationLevel == 0 || participationLevel == 1)) {
initialLevel = "0"; // 能力完好
} else if (activityLevel == 0 && (mentalStateLevel >= 1 || sensoryCommunicationLevel >= 1 || participationLevel == 2)) {
initialLevel = "1"; // 轻度失能
} else if ((activityLevel == 1 && (mentalStateLevel <= 1 || sensoryCommunicationLevel <= 1 || participationLevel <= 1)) ||
(activityLevel == 1 && mentalStateLevel == 2 && sensoryCommunicationLevel == 2 && participationLevel == 2) ||
(activityLevel == 2 && (mentalStateLevel == 1 || sensoryCommunicationLevel == 1 || participationLevel == 1 || mentalStateLevel == 2 || sensoryCommunicationLevel == 2))) {
initialLevel = "2"; // 中度失能
} else if (activityLevel == 3 ||
(activityLevel == 2 && (mentalStateLevel == 3 || sensoryCommunicationLevel == 3 || participationLevel == 3)) ||
(mentalStateLevel == 2 && sensoryCommunicationLevel == 2 && participationLevel == 2)) {
initialLevel = "3"; // 重度失能
}
// 输出初步等级
System.out.println("Initial Level: " + initialLevel);
// 将初步等级存储到请求中,并跳转到结果页面
req.setAttribute("initialLevel", initialLevel);
req.getRequestDispatcher("result.jsp").forward(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doPost(req, resp);
}
}
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>能力等级评估结果</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #E0F7FA; /* 浅湖蓝色背景 */
padding: 20px;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
max-width: 800px;
padding: 20px;
background-color: white;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
width: 100%;
}
h1 {
text-align: center;
color: #00ACC1; /* 湖蓝色 */
margin-bottom: 20px;
}
.result-table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
.result-table th, .result-table td {
border: 1px solid #ddd;
padding: 12px;
text-align: center;
}
.result-table th {
background-color: #f2f2f2;
}
.level {
font-weight: bold;
color: #00ACC1; /* 湖蓝色 */
}
.error-message {
color: red;
text-align: center;
margin: 10px 0;
}
.button {
background-color: #00ACC1;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
margin-top: 20px;
}
.button:hover {
background-color: #0097A7;
}
</style>
</head>
<body>
<div class="container">
<h1>能力等级评估结果</h1>
<!-- 错误信息提示 -->
<c:if test="${not empty errorMessage}">
<div class="error-message">
<p>${errorMessage}</p>
</div>
</c:if>
<!-- 评估结果表格 -->
<table class="result-table">
<thead>
<tr>
<th>评估项目</th>
<th>等级</th>
</tr>
</thead>
<tbody>
<tr>
<td>日常生活活动</td>
<td class="level">
${activityLevel == 0 ? '能力完好' :
activityLevel == 1 ? '轻度受损' :
activityLevel == 2 ? '中度受损' : '重度受损'}
</td>
</tr>
<tr>
<td>精神状态</td>
<td class="level">
${mentalStateLevel == 0 ? '能力完好' :
mentalStateLevel == 1 ? '轻度受损' :
mentalStateLevel == 2 ? '中度受损' : '重度受损'}
</td>
</tr>
<tr>
<td>感知觉与沟通</td>
<td class="level">
${sensoryCommunicationLevel == 0 ? '能力完好' :
sensoryCommunicationLevel == 1 ? '轻度受损' :
sensoryCommunicationLevel == 2 ? '中度受损' :
'重度受损'}
</td>
</tr>
<tr>
<td>社会参与</td>
<td class="level">
${participationLevel == 0 ? '能力完好' :
participationLevel == 1 ? '轻度受损' :
participationLevel == 2 ? '中度受损':
'重度受损'}
</td>
</tr>
<tr>
<td>能力初步等级</td>
<td class="level">
${initialLevel == 0 ? '能力完好' :
initialLevel == 1 ? '轻度失能' :
initialLevel == 2 ? '中度失能' : '重度失能'}
</td>
</tr>
</tbody>
</table>
<!-- 提示按钮 -->
<c:if test="${not empty errorMessage}">
<button class="button" onclick="window.history.back()">返回</button>
</c:if>
</div>
</body>
</html>

浙公网安备 33010602011771号