lsp66

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

继续对b2表格进行创建
mentalStatus.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;
}
‌MentalStatus.java‌
public class MentalStatus {
private int cognitiveFunction;
private int aggressiveBehavior;
private int depressiveSymptoms;

// Getters and Setters
public int getCognitiveFunction() {
    return cognitiveFunction;
}

public void setCognitiveFunction(int cognitiveFunction) {
    this.cognitiveFunction = cognitiveFunction;
}

public int getAggressiveBehavior() {
    return aggressiveBehavior;
}

public void setAggressiveBehavior(int aggressiveBehavior) {
    this.aggressiveBehavior = aggressiveBehavior;
}

public int getDepressiveSymptoms() {
    return depressiveSymptoms;
}

public void setDepressiveSymptoms(int depressiveSymptoms) {
    this.depressiveSymptoms = depressiveSymptoms;
}

// Calculate total score
public int getTotalScore() {
    return cognitiveFunction + aggressiveBehavior + depressiveSymptoms;
}

}
‌MentalStatusServlet.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("/submitMentalStatus")
public class MentalStatusServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
MentalStatus mentalStatus = new MentalStatus();
mentalStatus.setCognitiveFunction(Integer.parseInt(request.getParameter("cognitiveFunction")));
mentalStatus.setAggressiveBehavior(Integer.parseInt(request.getParameter("aggressiveBehavior")));
mentalStatus.setDepressiveSymptoms(Integer.parseInt(request.getParameter("depressiveSymptoms")));

    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 mental_status (cognitive_function, aggressive_behavior, depressive_symptoms) VALUES (?, ?, ?)";
        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.setInt(1, mentalStatus.getCognitiveFunction());
        pstmt.setInt(2, mentalStatus.getAggressiveBehavior());
        pstmt.setInt(3, mentalStatus.getDepressiveSymptoms());
        pstmt.executeUpdate();

        conn.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    response.sendRedirect("mentalStatus.jsp");
}

}

posted on 2025-02-20 18:28  李世鹏66  阅读(24)  评论(0)    收藏  举报