数据库程序设计第七天--隔离地权限

一、说在前面

  今天的目标是完成隔离地对隔离人员的相关操作以及对自身信息的操作

二、任务进度

package Servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

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 Bean.IsolatedAreaBean;
import Bean.PersonBean;
import Dao.IPDao;
import Dao.IsolatedAreaDao;

/**
 * Servlet implementation class AreaMessegServlet
 */
@WebServlet("/areaMessegServlet")
public class AreaMessegServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AreaMessegServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        List<IsolatedAreaBean> list=new ArrayList();
        String wname=request.getParameter("wname");
        IsolatedAreaDao idao=new IsolatedAreaDao();
        list=idao.list(wname);
        request.setAttribute("list", list);
        request.getRequestDispatcher("areaMessegShow.jsp").forward(request, response);
        
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}
AreaMessageServlet
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="layui/layui.css" >
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="layui/layui.js"></script>
<script src="layui/layui.all.js"></script>

<title>用户管理</title>
</head>
<body>
<% 
    Object message = request.getAttribute("message");
    Object list    =request.getAttribute("list");
    if(message!=null && !"".equals(message)){
%>
    <script type="text/javascript">
        alert("<%=request.getAttribute("message")%>");
    </script>
<% 
    }
%>
<table class="layui-table">
  <colgroup>
    <col width="50">
    <col width="150">
    <col width="150">
    <col width="150">
    <col width="150">
    <col width="350">
    <col width="150">
  </colgroup>
  <thead>
    <tr>
      <th>WID</th>
      <th>隔离地名称</th>
      <th>隔离人员最大容量</th>
      <th>已住隔离人员人数</th>
      <th>对应医院</th>
      <th>地址</th>
    </tr> 
  </thead>
  <tbody>
      
    <c:forEach var="item" items="${list}">
        <tr>
            <td>${item.wid}</td>
            <td>${item.wname}</td>
            <td>${item.capacity}</td>
            <td>${item.residents}</td>
            <td>${item.hospital}</td>
            <td>${item.address}</td>
             
        </tr>
    </c:forEach>
  </tbody>
</table>
</body>
</html>
areamessageShow
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>修改用户信息</title>
<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
<script src="layui/layui.all.js"></script>
<link rel="stylesheet" href="layui/layui.css" >
<style>
    #show{
        /* background-color:yellow;  */
        margin-top: 50px;
        margin-left: 100px;
        width: 425px;
    }
</style>
</head>
<body>
<div id="show" >
<form action="updateAreaServlet" class="layui-form" id="form">
    <div class="layui-form-item">
    <label class="layui-form-label">WID</label>
    <div class="layui-input-inline">
      <input type="text" name="wid" required  lay-verify="required" value="${param.wid}" autocomplete="off"   readonly="true" class="layui-input" style="color:#999999" >
    </div>
      </div>
    <div class="layui-form-item">
    <label class="layui-form-label">隔离地名称</label>
    <div class="layui-input-inline">
      <input type="text" name="wname" required  lay-verify="required" value="${param.wname}" autocomplete="off"   class="layui-input" >
    </div>
      </div>
      <div class="layui-form-item">
    <label class="layui-form-label">最大容量</label>
    <div class="layui-input-inline">
      <input type="text" name="capacity" required lay-verify="required" value="${param.capacity}" autocomplete="off"   class="layui-input" >
       </div>
       </div>
       <div class="layui-form-item">
    <label class="layui-form-label">已住人数</label>
    <div class="layui-input-inline">
      <input type="text" name="residents" required lay-verify="required" value="${param.residents}" autocomplete="off" class="layui-input">
       </div>
       </div>
       <div class="layui-form-item">
    <label class="layui-form-label">对应医院</label>
    <div class="layui-input-inline">
      <input type="text" name="hospital" required lay-verify="required" value="${param.hospital}" autocomplete="off" class="layui-input">
       </div>
       </div>
       <div class="layui-form-item">
    <label class="layui-form-label">地址</label>
    <div class="layui-input-inline">
      <input type="text" name="address" required lay-verify="required" value="${param.address}" autocomplete="off" class="layui-input">
       </div>
       </div>
       <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
     </div>
</form>
</div>
</body>
<script>
//Demo
layui.use('form', function(){
  //alert(${param.wid});
  var form = layui.form;
  
  //监听提交
  form.on('submit(formDemo)', function(data){
    layer.msg(JSON.stringify(data.field));
    return true;
  });
});

</script>
</html>
update_area
package Servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

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 Bean.IsolatedAreaBean;
import Bean.PersonBean;
import Dao.IPDao;
import Dao.IsolatedAreaDao;

/**
 * Servlet implementation class AreaShowServlet
 */
@WebServlet("/areaShowServlet")
public class AreaShowServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AreaShowServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        List<PersonBean> list=new ArrayList();
        String wname=request.getParameter("wname");
        IPDao dao=new IPDao();
        list=dao.list(wname);
        request.setAttribute("list", list);
        request.getRequestDispatcher("personShow.jsp").forward(request, response);
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}
AreaShowServlet
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="layui/layui.css" >
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="layui/layui.js"></script>
<script src="layui/layui.all.js"></script>

<title>用户管理</title>
</head>
<body>
<% 
    Object message = request.getAttribute("message");
    Object list    =request.getAttribute("list");
    if(message!=null && !"".equals(message)){
%>
    <script type="text/javascript">
        alert("<%=request.getAttribute("message")%>");
    </script>
<% 
    }
%>
<table class="layui-table">
  <colgroup>
    <col width="50">
    <col width="150">
    <col width="90">
    <col width="150">
    <col width="150">
    <col width="150">
    <col width="150">
    <col width="150">
    <col width="150">
  </colgroup>
  <thead>
    <tr>
      <th>PID/WID</th>
      <th>姓名</th>
      <th>性别</th>
      <th>出生日期</th>
      <th>隔离日期</th>
      <th>结束日期</th>
      <th>隔离地</th>
      <th>来源地</th>
      <th>备注</th>
      <th>操作</th>
    </tr> 
  </thead>
  <tbody>
      <tr>
          <form action="insertPersonServlet" class="layui-form" id="form" >
              <td></td>
              <td><input type="text" id="pname" name="pname" required  lay-verify="required" autocomplete="off" class="layui-input"></td>
              <td><input type="text" id="sex" name="sex" required  lay-verify="required" autocomplete="off" class="layui-input"></td>
              <td><input type="date" id="birth" name="birth" required  lay-verify="required" autocomplete="off" class="layui-input"></td>
              <td><input type="date" id="startdate" name="startdate" required  lay-verify="required" autocomplete="off" class="layui-input"></td>
              <td><input type="date" id="enddate" name="enddate" required lay-verify="required" autocomplete="off" class="layui-input"></td>
              <td><input type="text" id="wname" name="wname" required  lay-verify="required" autocomplete="off" class="layui-input"></td>
              <td><input type="text" id="from" name="from" required  lay-verify="required" autocomplete="off" class="layui-input"></td>
              <td><input type="text" id="eg" name="eg" required  lay-verify="required" autocomplete="off" class="layui-input"></td>
              <td><button type="submit" class="layui-btn" lay-submit lay-filter="formDemo" ><i class="layui-icon " style="font-size: 23px; color: white;">&nbsp;&nbsp;&#xe624;&nbsp;</i></button></td>

          </form>
      </tr>
    <c:forEach var="item" items="${list}">
        <tr>
            <td>${item.pid}/${item.wid}</td>
            <td>${item.pname}</td>
            <td>${item.sex}</td>
            <td>${item.birth}</td>
            <td>${item.startday}</td>
            <td>${item.endday}</td>
            <td>${item.wname}</td>
            <td>${item.from}</td>
            <td>${item.eg}</td>
             <td><a href="#" target="_self"> <button type="button" class="layui-btn layui-btn-sm"><i class="layui-icon" style="font-size: 23px; color: white;">&#xe642;</i></button></a>
                <a href="deletePersonServlet?pid=${item.pid}&wid=${item.wid}" onclick="return confirm('确定删除么')"><button type="button" class="layui-btn layui-btn-danger layui-btn-sm"><i class="layui-icon" style="font-size: 23px; color: white;">&#xe640;</i></button></a>
            </td> 
        </tr>
    </c:forEach>
  </tbody>
</table>
</body>
</html>
personShowServlet
package Servlet;

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 Bean.IsolatedAreaBean;
import Bean.PersonBean;
import Dao.InformationDao;
import Dao.IsolatedAreaDao;
import Dao.PersonDao;

/**
 * Servlet implementation class InsertPersonServlet
 */
@WebServlet("/insertPersonServlet")
public class InsertPersonServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public InsertPersonServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        String pname=request.getParameter("pname");
        String sex=request.getParameter("sex");
        String birth=request.getParameter("birth");
        String startdate=request.getParameter("startdate");
        String enddate=request.getParameter("enddate");
        String wname=request.getParameter("wname");
        String from=request.getParameter("from");
        String eg=request.getParameter("eg");
        PersonBean person=null;
        PersonDao pdao=new PersonDao();
        IsolatedAreaDao idao=new IsolatedAreaDao();
        InformationDao infoDao=new InformationDao();
        if(!pdao.search(pname)) {
            person=new PersonBean(pname,sex,birth);
            pdao.insert(person);
        }
        if(!idao.search(wname)) {
            request.setAttribute("message", "添加失败,不存在对应隔离地");
            request.getRequestDispatcher("peopleShowServlet").forward(request, response);
        }else {
            int pid=pdao.select(pname);
            int wid=idao.select(wname);
            System.out.println(pid+"---->"+wid);
            person=new PersonBean(pid,wid,startdate,enddate,from,eg);
            infoDao.insert(person);
            request.setAttribute("message", "添加成功");
            request.getRequestDispatcher("peopleShowServlet").forward(request, response);
        }
        
        
        

        
        
        
        
        
        
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}
insertPersonServlet

 

posted @ 2020-07-16 11:17  酸奶面包  阅读(154)  评论(0编辑  收藏  举报