2月8日学习总结——老年人评估系统4

今天完成了信息提供者表单及相关功能

package org.example.oldmandemo3;

public class information {
    private String name;
    private String relation;
    private String contacts;
    private String phone;
    private String number;
    private String idnumber;

    public information(String name, String relation, String contacts, String phone,String number,String idnumber) {
        this.name = name;
        this.relation = relation;
        this.contacts = contacts;
        this.phone = phone;
        this.number = number;
        this.idnumber = idnumber;
    }

    public String getName() {
        return name;
    }

    public String getRelation() {
        return relation;
    }

    public String getContacts() {
        return contacts;
    }

    public String getPhone() {
        return phone;
    }

    public String getNumber() {return number;}

    public String getIdnumber() {return idnumber;}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>填写信息提供者及联系人信息</title>
    <meta charset="UTF-8">
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 450px;
        }
        h2 {
            text-align: center;
            color: #333;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            color: #666;
        }
        input[type="text"], select {
            width: 100%;
            padding: 8px;
            box-sizing: border-box;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        input[type="submit"] {
            width: 100%;
            padding: 10px;
            background-color: #0056b3;
            border: none;
            border-radius: 4px;
            color: white;
            font-size: 16px;
            cursor: pointer;
        }
        input[type="submit"]:hover {
            background-color: #0056b3;
        }
        .other-relation-field {
            display: none;
            margin-top: 5px;
        }
    </style>
    <script>
        function showAdditionalFields() {
            const relationSelect = document.getElementById('relation');
            const otherrelation = document.getElementById('otherrelation');

            if (relationSelect.value === '其他') {
                otherrelation.style.display = 'block';
            } else {
                otherrelation.style.display = 'none';
            }
        }

        document.addEventListener('DOMContentLoaded', function() {
            const relationSelect = document.getElementById("relation");

            relationSelect.addEventListener('change', showAdditionalFields);

            showAdditionalFields();
        });
    </script>
</head>
<body>
<form action="addinformation" method="post">
    <div class="container">
        <h2>填写信息提供者及联系人信息表</h2>

        <div class="form-group">
            <label for="name">信息提供者的姓名:</label>
            <input name="name" type="text" id="name">
        </div>

        <div class="form-group">
            <label for="relation">信息提供者与老人的关系:</label>
            <select name="relation" id="relation">
                <option value="配偶">配偶</option>
                <option value="子女">子女</option>
                <option value="其他亲属">其他亲属</option>
                <option value="雇佣照顾者">雇佣照顾者</option>
                <option value="其他">其他</option>
            </select>

            <label for="otherrelation" class="other-relation-field"></label>
            <input name="otherrelation" type="text" id="otherrelation" class="other-relation-field">
        </div>

        <div class="form-group">
            <label for="contacts">联系人姓名:</label>
            <input name="contacts" type="text" id="contacts">
        </div>

        <div class="form-group">
            <label for="phone">联系人电话:</label>
            <input name="phone" type="text" id="phone">
        </div>

        <input type="hidden" name="number" value="<%=session.getAttribute("number")%>">
        <input type="hidden" name="idnumber" value="<%=session.getAttribute("idnumber")%>">

        <div class="form-group">
            <input type="submit" value="完成">
        </div>

    </div>
</form>
</body>
</html>
<%@ page import="org.example.oldmandemo3.information" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>老年人能力评估系统-查看信息提供者及联系人信息表</title>
  <meta charset="UTF-8">
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f9;
      margin: 0;
      padding: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
    }
    .container {
      background-color: rgba(255, 255, 255, 0.9);
      padding: 20px;
      border-radius: 8px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
      width: 100%;
      max-width: 800px;
      text-align: left;
    }
    h2 {
      font-size: 1.5em;
      margin-bottom: 20px;
      text-align: center;
    }
    form {
      display: flex;
      flex-direction: column;
      gap: 10px;
    }
    label {
      font-weight: bold;
      margin-bottom: 5px;
    }
    input[type="text"], input[type="date"], select {
      padding: 8px;
      border: 1px solid #ccc;
      border-radius: 4px;
      box-sizing: border-box;
      width: 100%;
    }
    input[type="submit"] {
      padding: 10px;
      background-color: #007BFF;
      color: white;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      font-size: 16px;
      transition: background-color 0.3s ease;
    }
    input[type="submit"]:hover {
      background-color: #0056b3;
    }
    table {
      width: 100%;
      border-collapse: collapse;
      margin-top: 20px;
    }
    th, td {
      border: 1px solid #ddd;
      padding: 8px;
      text-align: left;
    }
    th {
      background-color: #f2f2f2;
    }
    tr:nth-child(even) {
      background-color: #f9f9f9;
    }
    tr:hover {
      background-color: #eaeaea;
    }
    .scrollable-container {
      overflow-x: auto;
    }
  </style>
  <script>
    function showAdditionalFields() {
      const relationSelect = document.getElementById('relation');
      const otherrelation = document.getElementById('otherrelation');

      if (relationSelect.value === '其他') {
        otherrelation.style.display = 'block';
      } else {
        otherrelation.style.display = 'none';
      }
    }

    document.addEventListener('DOMContentLoaded', function() {
      const relationSelect = document.getElementById("relation");
      relationSelect.addEventListener('change', showAdditionalFields);
      showAdditionalFields();
    });
  </script>
</head>
<body>
<div class="container">
  <h2>查看信息提供者及联系人信息表</h2>
  <form action="checkinformation" method="get">
    <%
      String type = request.getParameter("type");
      String idnumber = request.getParameter("idnumber");
      if (type.equals("评估员") || type.equals("管理员")) {
    %>
    <label for="checknumber">评估编号:</label>
    <input name="number" type="text" id="checknumber">
    <% } else { %>
    <input name="idnumber" type="hidden" value="<%= idnumber %>">
    <% } %>

    <input name="type" type="hidden" value="<%= type %>">
    <input type="submit" value="查看">
  </form>
  <div class="scrollable-container">
    <table border="1">
      <tr>
        <th>信息提供者的姓名</th>
        <th>信息提供者与老人的关系</th>
        <th>联系人姓名</th>
        <th>联系人电话</th>
      </tr>
      <%
        List<information> data = (List<information>) request.getAttribute("data");
        if (data != null && !data.isEmpty()) {
          for (information d : data) { %>
      <tr>
        <td><%= d.getName() %></td>
        <td><%= d.getRelation() %></td>
        <td><%= d.getContacts() %></td>
        <td><%= d.getPhone() %></td>
        <td>
          <form action="changeinformation" method="post" class="edit-form">
            <input name="number" type="hidden" value="<%= d.getNumber() %>">
            <label for="name">信息提供者的姓名:</label>
            <input name="name" type="text" id="name" value="<%= d.getName() %>">
            <label for="relation">信息提供者与老人的关系:</label>
            <select name="relation" id="relation" onchange="showAdditionalFields()">
              <option value="配偶" <%= "配偶".equals(d.getRelation()) ? "selected" : "" %>>配偶</option>
              <option value="子女" <%= "子女".equals(d.getRelation()) ? "selected" : "" %>>子女</option>
              <option value="其他亲属" <%= "其他亲属".equals(d.getRelation()) ? "selected" : "" %>>其他亲属</option>
              <option value="雇佣照顾者" <%= "雇佣照顾者".equals(d.getRelation()) ? "selected" : "" %>>雇佣照顾者</option>
              <option value="其他" <%= "其他".equals(d.getRelation()) ? "selected" : "" %>>其他</option>
            </select>
            <input name="otherrelation" type="text" id="otherrelation" style="display: <%= "其他".equals(d.getRelation()) ? "block" : "none" %>;">
            <label for="contacts">联系人姓名:</label>
            <input name="contacts" type="text" id="contacts" value="<%= d.getContacts() %>">
            <label for="phone">联系人电话:</label>
            <input name="phone" type="text" id="phone" value="<%= d.getPhone() %>">
            <input type="submit" value="修改">
          </form>
        </td>
      </tr>
      <% }
      } else { %>
      <tr>
        <td colspan="4" style="text-align:center;">暂无数据</td>
      </tr>
      <% } %>
    </table>
  </div>
</div>
</body>
</html>
package org.example.oldmandemo3;

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.io.IOException;
import java.sql.SQLException;

@WebServlet("/addinformation")
public class addinformation extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");

        String name = request.getParameter("name");
        String relation= request.getParameter("relation");
        if(relation.equals("其他")) relation=request.getParameter("otherrelation");
        String contacts = request.getParameter("contacts");
        String phone= request.getParameter("phone");
        String number= request.getParameter("number");
        String idnumber= request.getParameter("idnumber");
        information data=new information(name,relation,contacts,phone,number,idnumber);
        Dao dao=new Dao();
        try {
            if(dao.addinformation(data)) {
                response.sendRedirect("mainpage.jsp");
            }
            else {
                request.getRequestDispatcher("addinformation.jsp").forward(request, response);
            }
        } catch (SQLException | ClassNotFoundException e) {
            throw new ServletException(e);
        }
    }
}
package org.example.oldmandemo3;

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.io.IOException;
import java.sql.SQLException;

@WebServlet("/changeinformation")
public class changeinformation extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");

        String name = request.getParameter("name");
        String relation= request.getParameter("relation");
        if(relation.equals("其他")) relation=request.getParameter("otherrelation");
        String contacts = request.getParameter("contacts");
        String phone= request.getParameter("phone");
        String number= request.getParameter("number");
        String idnumber= request.getParameter("idnumber");
        information data=new information(name,relation,contacts,phone,number,idnumber);
        Dao dao=new Dao();
        try {
            dao.changeinformation(data);
            response.sendRedirect("mainpage.jsp");
        } catch (SQLException | ClassNotFoundException e) {
            throw new ServletException(e);
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        super.doGet(request, response);
    }
}
package org.example.oldmandemo3;

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.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/checkinformation")
public class checkinformation extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");

        String type = request.getParameter("type");
        String number;
        if(type.equals("评估员")||type.equals("管理员")) number = request.getParameter("number");
        else number = request.getParameter("idnumber");
        Dao dao = new Dao();
        try {
            List<information> data=dao.checkinformation(type,number);
            request.setAttribute("data", data);
        } catch (SQLException | ClassNotFoundException e) {
            e.printStackTrace();
        }
        request.getRequestDispatcher("checkinformation.jsp").forward(request,response);
    }
}
posted @   离璨霂  阅读(3)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」
点击右上角即可分享
微信分享提示