人口信息删除功能实现
界面:
界面设计同人口信息修改,两者的查询条件是同一套查询方式,同样是采用frame框架组合搭建。
源码:
查询条件界面:
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="utf-8"> 7 <title>Insert title here</title> 8 9 <link rel="stylesheet" href="layui/css/layui.css" media="all"> 10 <script src="layui/layui.js" type="text/javascript"></script> 11 <script src="jquery/jquery-1.9.1.min.js" type="text/javascript"></script> 12 13 </head> 14 <body> 15 <form class="layui-form" action="PeopleSelectDelServlet" target="deldown" method="post"> 16 <br> 17 <br> 18 <h1 align="center">第七次全国人口普查-人口信息删除</h1> 19 <br> 20 <br> 21 <table> 22 <tr> 23 <td> 24 <!-- 姓名 --> 25 <div class="layui-form-item"> 26 <label class="layui-form-label">户主姓名:</label> 27 <div class="layui-input-inline"> 28 <input type="text" name="HZXM" placeholder="请输入户主姓名" autocomplete="off" class="layui-input"> 29 </div> 30 </div> 31 </td> 32 <td> 33 <!-- 提交 --> 34 <div class="layui-form-item"> 35 <div class="layui-input-block"> 36 <button class="layui-btn" lay-submit lay-filter="formDemo">查询</button> 37 </div> 38 </div> 39 </td> 40 </tr> 41 </table> 42 </form> 43 <script> 44 //Demo 45 layui.use('form', function(){ 46 var form = layui.form; 47 48 //监听提交 49 50 }); 51 </script> 52 </body> 53 </html>
展示界面源代码:
1 <%@page import="entity.People"%> 2 <%@page import="java.util.List"%> 3 4 <%@ page language="java" contentType="text/html; charset=utf-8" 5 pageEncoding="utf-8"%> 6 <!DOCTYPE html> 7 <html> 8 <head> 9 <meta charset="utf-8"> 10 <title>Insert title here</title> 11 12 <link rel="stylesheet" href="layui/css/layui.css" media="all"> 13 <script src="layui/layui.js" type="text/javascript"></script> 14 <script src="jquery/jquery-1.9.1.min.js" type="text/javascript"></script> 15 16 17 </head> 18 <body> 19 <form class="layui-form" action="PeopleDelServlet" method="post"> 20 <% 21 List<People> list =(List<People>)request.getAttribute("list1"); 22 %> 23 <table class="layui-table"> 24 <colgroup> 25 <col width="150"> 26 <col width="200"> 27 <col width="250"> 28 <col width="300"> 29 <col> 30 </colgroup> 31 <% 32 if(list==null){ 33 %> 34 <tr> 35 <td colspan="2" align="center"><label>暂无查找记录</label></td> 36 </tr> 37 <% 38 } 39 else{ 40 41 People p=list.get(0); 42 %> 43 44 <tr> 45 <td>户主姓名:</td><td><%= p.getHZXM() %></td> 46 </tr> 47 <tr> 48 <th>性别</th><td><%= p.getXB() %></td> 49 </tr> 50 <tr> 51 <th>民族</th><td><%= p.getMZ() %></td> 52 </tr> 53 <tr> 54 <th>受教育程度</th><td><%= p.getSJYCD() %></td> 55 </tr> 56 57 <input name="HZXM" value=<%= p.getHZXM() %> type="hidden"> 58 59 <% 60 } 61 %> 62 </table> 63 64 65 <!-- 提交 --> 66 <div class="layui-form-item"> 67 <div class="layui-input-block"> 68 <button class="layui-btn" lay-submit lay-filter="formDemo" onclick="javascript:return del()">删除</button> 69 </div> 70 </div> 71 </form> 72 <script type="text/javascript"> 73 function del() { 74 var msg = "您真的确定要删除吗? 请确认!"; 75 if (confirm(msg)==true){ 76 return true; 77 }else{ 78 return false; 79 } 80 } 81 </script> 82 </body> 83 </html>
接口实现:
1 @Override 2 public boolean delete(String HZXM) { 3 // TODO Auto-generated method stub 4 boolean flag=false; 5 try { 6 String sql="delete from huseventhpeoplecheck where HZXM='"+HZXM+"'"; 7 PreparedStatement pstmt = conn.prepareStatement(sql); 8 int i=pstmt.executeUpdate(); 9 pstmt.close(); 10 conn.close(); 11 if(i>0) 12 flag=true; 13 }catch(SQLException e){ 14 System.out.println("人口信息删除失败!!!"); 15 e.printStackTrace(); 16 } 17 return flag; 18 }
servlet实现:
1 package service; 2 3 import java.io.IOException; 4 import javax.servlet.ServletException; 5 import javax.servlet.annotation.WebServlet; 6 import javax.servlet.http.HttpServlet; 7 import javax.servlet.http.HttpServletRequest; 8 import javax.servlet.http.HttpServletResponse; 9 10 import dao.PeopleDao; 11 import dao.PeopleDaoImpI; 12 13 /** 14 * Servlet implementation class PeopleDelServlet 15 */ 16 @WebServlet("/PeopleDelServlet") 17 public class PeopleDelServlet extends HttpServlet { 18 private static final long serialVersionUID = 1L; 19 20 /** 21 * @see HttpServlet#HttpServlet() 22 */ 23 public PeopleDelServlet() { 24 super(); 25 // TODO Auto-generated constructor stub 26 } 27 28 /** 29 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 30 */ 31 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 32 // TODO Auto-generated method stub 33 doPost(request, response); 34 } 35 36 /** 37 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 38 */ 39 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 40 request.setCharacterEncoding("utf-8"); 41 response.setContentType("text/html;charset=utf-8"); 42 43 String HZXM = request.getParameter("HZXM"); 44 PeopleDao pd = new PeopleDaoImpI(); 45 System.out.println(HZXM); 46 47 try { 48 pd.delete(HZXM); 49 response.sendRedirect("showdel.jsp"); 50 System.out.println("人口删除成功!!!"); 51 52 }catch(Exception e){ 53 System.out.println("人口信息删除失败!!!"); 54 e.printStackTrace(); 55 } 56 57 58 } 59 60 }
最终效果:
点击确定删除之后,实现人口信息的删除
至此,人口信息删除功能得以实现