继续对c.4进行创建
elderlyFinalLevel.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
老年人能力最终等级评估
styles.css body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 0; }h1 {
text-align: center;
color: #333;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
select {
width: 100%;
padding: 8px;
box-sizing: border-box;
}
button {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
2. 后台技术:JavaBean
FinalLevelBean.java
public class FinalLevelBean {
private int dailyLiving;
private int mentalStatus;
private int sensoryCommunication;
private int socialInvolvement;
private int finalLevel;
// Getters and Setters
public int getDailyLiving() {
return dailyLiving;
}
public void setDailyLiving(int dailyLiving) {
this.dailyLiving = dailyLiving;
}
public int getMentalStatus() {
return mentalStatus;
}
public void setMentalStatus(int mentalStatus) {
this.mentalStatus = mentalStatus;
}
public int getSensoryCommunication() {
return sensoryCommunication;
}
public void setSensoryCommunication(int sensoryCommunication) {
this.sensoryCommunication = sensoryCommunication;
}
public int getSocialInvolvement() {
return socialInvolvement;
}
public void setSocialInvolvement(int socialInvolvement) {
this.socialInvolvement = socialInvolvement;
}
public int getFinalLevel() {
return finalLevel;
}
public void setFinalLevel(int finalLevel) {
this.finalLevel = finalLevel;
}
}
第二天学习记录:老年人能力最终等级的后台逻辑处理及结果展示
- 后台技术:Servlet
FinalLevelServlet.java
import java.io.IOException;
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;
@WebServlet("/submitFinalLevel")
public class FinalLevelServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
FinalLevelBean finalLevelBean = new FinalLevelBean();
finalLevelBean.setDailyLiving(Integer.parseInt(request.getParameter("dailyLiving")));
finalLevelBean.setMentalStatus(Integer.parseInt(request.getParameter("mentalStatus")));
finalLevelBean.setSensoryCommunication(Integer.parseInt(request.getParameter("sensoryCommunication")));
finalLevelBean.setSocialInvolvement(Integer.parseInt(request.getParameter("socialInvolvement")));
determineFinalLevel(finalLevelBean);
HttpSession session = request.getSession();
session.setAttribute("finalLevelBean", finalLevelBean);
response.sendRedirect("resultFinalLevel.jsp");
}
private void determineFinalLevel(FinalLevelBean finalLevelBean) {
int dailyLiving = finalLevelBean.getDailyLiving();
int mentalStatus = finalLevelBean.getMentalStatus();
int sensoryCommunication = finalLevelBean.getSensoryCommunication();
int socialInvolvement = finalLevelBean.getSocialInvolvement();
int finalLevel = 0;
if (dailyLiving == 3 || mentalStatus == 3 || sensoryCommunication == 3 || socialInvolvement == 3) {
finalLevel = 3; // 重度失能
} else if ((dailyLiving == 2 && (mentalStatus == 2 || sensoryCommunication == 2 || socialInvolvement == 2))
|| (dailyLiving == 2 && (mentalStatus == 3 || sensoryCommunication == 3 || socialInvolvement == 3))
|| (dailyLiving == 1 && (mentalStatus == 2 || sensoryCommunication == 2 || socialInvolvement == 2))
|| (dailyLiving == 1 && (mentalStatus == 3 || sensoryCommunication == 3 || socialInvolvement == 3))) {
finalLevel = 2; // 中度失能
} else if ((dailyLiving == 1 && (mentalStatus == 1 || sensoryCommunication == 1 || socialInvolvement == 1))
|| (dailyLiving == 1 && (mentalStatus == 0 || sensoryCommunication == 0 || socialInvolvement == 0))
|| (dailyLiving == 0 && (mentalStatus == 2 || sensoryCommunication == 2 || socialInvolvement == 2))
|| (dailyLiving == 0 && (mentalStatus == 3 || sensoryCommunication == 3 || socialInvolvement == 3))) {
finalLevel = 1; // 轻度失能
} else {
finalLevel = 0; // 能力完好
}
finalLevelBean.setFinalLevel(finalLevel);
}
}
浙公网安备 33010602011771号