继续对b3表进行创建
sensoryCommunication.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: 20px; }h1 {
color: #333;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
}
select {
width: 100%;
padding: 8px;
box-sizing: border-box;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
cursor: pointer;
width: 100%;
}
button:hover {
background-color: #45a049;
}
2. 后台技术:JavaBean + Servlet
SensoryCommunication.java
public class SensoryCommunication {
private int levelOfConsciousness;
private int vision;
private int hearing;
private int communication;
// Getters and Setters
public int getLevelOfConsciousness() {
return levelOfConsciousness;
}
public void setLevelOfConsciousness(int levelOfConsciousness) {
this.levelOfConsciousness = levelOfConsciousness;
}
public int getVision() {
return vision;
}
public void setVision(int vision) {
this.vision = vision;
}
public int getHearing() {
return hearing;
}
public void setHearing(int hearing) {
this.hearing = hearing;
}
public int getCommunication() {
return communication;
}
public void setCommunication(int communication) {
this.communication = communication;
}
// Determine the overall classification
public String getOverallClassification() {
if (levelOfConsciousness == 0 && vision <= 1 && hearing <= 1 && communication <= 0) {
return "0"; // 能力完好
} else if (levelOfConsciousness == 0 && (vision == 2 || hearing == 2 || communication == 1)) {
return "1"; // 轻度受损
} else if ((levelOfConsciousness == 1 || levelOfConsciousness == 2) && vision <= 3 && hearing <= 3 && communication <= 2) {
return "2"; // 中度受损
} else {
return "3"; // 重度受损
}
}
}
SensoryCommunicationServlet.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 java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
@WebServlet("/submitSensoryCommunication")
public class SensoryCommunicationServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
SensoryCommunication sensoryCommunication = new SensoryCommunication();
sensoryCommunication.setLevelOfConsciousness(Integer.parseInt(request.getParameter("levelOfConsciousness")));
sensoryCommunication.setVision(Integer.parseInt(request.getParameter("vision")));
sensoryCommunication.setHearing(Integer.parseInt(request.getParameter("hearing")));
sensoryCommunication.setCommunication(Integer.parseInt(request.getParameter("communication")));
try {
// Database connection
String url = "jdbc:oracle:thin:@//localhost:1521/xe";
String user = "your_username";
String password = "your_password";
Connection conn = DriverManager.getConnection(url, user, password);
String sql = "INSERT INTO sensory_communication (level_of_consciousness, vision, hearing, communication, classification) VALUES (?, ?, ?, ?, ?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, sensoryCommunication.getLevelOfConsciousness());
pstmt.setInt(2, sensoryCommunication.getVision());
pstmt.setInt(3, sensoryCommunication.getHearing());
pstmt.setInt(4, sensoryCommunication.getCommunication());
pstmt.setString(5, sensoryCommunication.getOverallClassification());
pstmt.executeUpdate();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
response.sendRedirect("sensoryCommunication.jsp");
}
}