继续对b1表进行创建
dailyActivities.jsp
jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
日常生活活动评估表
styles.css body { font-family: Arial, sans-serif; margin: 40px; }h1 {
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 {
padding: 10px 15px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
DailyActivity.java
public class DailyActivity {
private int eating;
private int bathing;
private int grooming;
private int dressing;
private int bowelControl;
private int bladderControl;
private int toileting;
private int bedChairTransfer;
private int flatGroundWalking;
private int stairs;
// Getters and Setters
public int getEating() {
return eating;
}
public void setEating(int eating) {
this.eating = eating;
}
// Similar getters and setters for other fields...
}
DailyActivityServlet.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("/submitActivities")
public class DailyActivityServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
DailyActivity activity = new DailyActivity();
activity.setEating(Integer.parseInt(request.getParameter("eating")));
activity.setBathing(Integer.parseInt(request.getParameter("bathing")));
activity.setGrooming(Integer.parseInt(request.getParameter("grooming")));
activity.setDressing(Integer.parseInt(request.getParameter("dressing")));
activity.setBowelControl(Integer.parseInt(request.getParameter("bowelControl")));
activity.setBladderControl(Integer.parseInt(request.getParameter("bladderControl")));
activity.setToileting(Integer.parseInt(request.getParameter("toileting")));
activity.setBedChairTransfer(Integer.parseInt(request.getParameter("bedChairTransfer")));
activity.setFlatGroundWalking(Integer.parseInt(request.getParameter("flatGroundWalking")));
activity.setStairs(Integer.parseInt(request.getParameter("stairs")));
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 daily_activities (eating, bathing, grooming, dressing, bowel_control, bladder_control, toileting, bed_chair_transfer, flat_ground_walking, stairs) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, activity.getEating());
pstmt.setInt(2, activity.getBathing());
pstmt.setInt(3, activity.getGrooming());
pstmt.setInt(4, activity.getDressing());
pstmt.setInt(5, activity.getBowelControl());
pstmt.setInt(6, activity.getBladderControl());
pstmt.setInt(7, activity.getToileting());
pstmt.setInt(8, activity.getBedChairTransfer());
pstmt.setInt(9, activity.getFlatGroundWalking());
pstmt.setInt(10, activity.getStairs());
pstmt.executeUpdate();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
response.sendRedirect("dailyActivities.jsp");
}
}