Java -web第七次人口普查征集系统开发日志六

人口信息浏览功能实现(1)

界面:

 

该界面相较于该系统的前几个功能界面有所不同,前几个界面需要用户向其中输入一些必要的数据,该界面是点击入口即可进入,并且直接执行写好的功能,并将结果进行展示。

 

源码:

界面源码:

 1 <%@page import="entity.People"%>
 2 <%@page import="java.util.List"%>
 3 
 4 
 5 <%@ page language="java" contentType="text/html; charset=utf-8"
 6     pageEncoding="utf-8"%>
 7 <!DOCTYPE html>
 8 <html>
 9 <head>
10 <meta charset="utf-8">
11 <title>第七次全国人口普查-人口信息浏览</title>
12 
13 <link rel="stylesheet" href="layui/css/layui.css" media="all">
14 <script src="layui/layui.js" type="text/javascript"></script>
15 <script src="jquery/jquery-1.9.1.min.js" type="text/javascript"></script>
16 
17 </head>
18 <body>
19 <h1 align="center">第七次全国人口普查-人口信息浏览</h1>
20 <form action="PeopleLiulanInfoServlet?method=doGet" method="post">
21 <%
22  List<People> list =(List<People>)request.getAttribute("list");
23  %>
24      <table class="layui-table">
25           <colgroup>
26             <col width="150">
27             <col width="200">
28             <col width="250">
29             <col>
30           </colgroup>
31           <thead>
32         <tr>
33               <th>户主姓名</th>
34               <th>性别</th>
35               <th>民族</th>
36               <th>受教育程度</th>
37         </tr> 
38           </thead>
39           <tbody>
40         <%
41         if(list==null){
42             %>
43             <tr>
44             <td colspan="4" align="center"><label>暂无查找记录</label></td>
45             </tr>
46         <% 
47         }
48         else{
49             for(int i=0;i<list.size();i++){
50                 People p=list.get(i);
51         %>
52             <tr>
53                 <td><a href="PeopleLiulanInfoServlet?HZXM=<%= p.getHZXM() %>"><%= p.getHZXM() %></a></td>
54                 <td><%= p.getXB() %></td>
55                 <td><%= p.getMZ() %></td>
56                 <td><%= p.getSJYCD() %></td>
57             </tr>
58         <%
59                 }
60             }
61         %>
62         </tbody>
63     </table>
64 
65 
66 </body>
67 </html>

 

 

 servlet源代码:

 1 package service;
 2 
 3 import java.io.IOException;
 4 import java.util.List;
 5 
 6 import javax.servlet.ServletException;
 7 import javax.servlet.annotation.WebServlet;
 8 import javax.servlet.http.HttpServlet;
 9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11 
12 import dao.PeopleDao;
13 import dao.PeopleDaoImpI;
14 import entity.People;
15 
16 
17 /**
18  * Servlet implementation class PeopleLiulanServlet
19  */
20 @WebServlet("/PeopleLiulanServlet")
21 public class PeopleLiulanServlet extends HttpServlet {
22     private static final long serialVersionUID = 1L;
23        
24     /**
25      * @see HttpServlet#HttpServlet()
26      */
27     public PeopleLiulanServlet() {
28         super();
29         // TODO Auto-generated constructor stub
30     }
31 
32     /**
33      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
34      */
35     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
36         // TODO Auto-generated method stub
37         doPost(request, response);
38     }
39 
40     /**
41      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
42      */
43     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
44         request.setCharacterEncoding("utf-8");
45         response.setContentType("text/html;charset=utf-8");
46         
47         PeopleDao pd = new PeopleDaoImpI();
48 
49         try {
50             List<People> people=pd.select();
51             request.setAttribute("list", people);
52             request.getRequestDispatcher("renkouliulan.jsp").forward(request, response);
53             System.out.println("人口查询成功!!!");
54         }catch(Exception e){
55             System.out.println("人口信息查询失败!!!");
56             e.printStackTrace();
57         }
58         
59     }
60 
61 }

这样就可以展示出数据库中所有人口信息的简略列表信息,并且是按照登陆时间排序。

 

效果截图:

 

posted @ 2020-11-22 15:18  wumingxiaozu  阅读(93)  评论(0编辑  收藏  举报