zoukankan      html  css  js  c++  java
  • Java-web第七次人口普查征集系统开发日志七

    人口浏览功能实现(2)

    点击列表显示中人口姓名,即可展示人口的详细信息

    实现方式,将人口姓名设置为超链接,通过超链接将前端的值传入对应的后端中,再将新的展示界面覆盖原来的界面

    效果:

    源码:

    界面源代码:

     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 </head>
    17 <body>
    18 <%
    19  List<People> list =(List<People>)request.getAttribute("list");
    20  %>
    21      <table class="layui-table">
    22           <colgroup>
    23             <col width="200">
    24             <col width="200">
    25             <col>
    26           </colgroup>
    27           <%
    28         if(list==null){
    29             %>
    30             <tr>
    31             <td colspan="2" align="center"><label>暂无查找记录111111</label></td>
    32             </tr>
    33         <% 
    34         }
    35         else{
    36             
    37                 People p=list.get(0);
    38         %>
    39           
    40         <tr>
    41               <td>户主姓名:</td><td><%= p.getHZXM() %></td>
    42           </tr>
    43           <tr>
    44               <th>性别</th><td><%= p.getXB() %></td>
    45           </tr>
    46           <tr>
    47               <th>民族</th><td><%= p.getMZ() %></td>
    48           </tr>
    49           <tr>
    50               <th>受教育程度</th><td><%= p.getSJYCD() %></td>
    51         </tr> 
    52         <tr>
    53               <th>户别</th><td><%= p.getHB() %></td>
    54         </tr> 
    55         <tr>
    56               <th>住房类型</th><td><%= p.getZFLX() %></td>
    57         </tr> 
    58         <tr>
    59               <th>现住房面积</th><td><%= p.getXZFMJ() %></td>
    60         </tr> 
    61         <tr>
    62               <th>现住房间数</th><td><%= p.getXZFJS() %></td>
    63         </tr> 
    64         
    65         <%
    66                 }
    67         %>
    68     </table>
    69     
    70     
    71 </body>
    72 </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 /**
    19  * Servlet implementation class PeopleLiulanInfoServlet
    20  */
    21 @WebServlet("/PeopleLiulanInfoServlet")
    22 public class PeopleLiulanInfoServlet extends HttpServlet {
    23     private static final long serialVersionUID = 1L;
    24        
    25     /**
    26      * @see HttpServlet#HttpServlet()
    27      */
    28     public PeopleLiulanInfoServlet() {
    29         super();
    30         // TODO Auto-generated constructor stub
    31     }
    32 
    33     /**
    34      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    35      */
    36     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    37         doPost(request, response);
    38         
    39     }
    40 
    41     /**
    42      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    43      */
    44     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    45         
    46         request.setCharacterEncoding("utf-8");
    47         response.setContentType("text/html;charset=utf-8");
    48         
    49         String HZXM=request.getParameter("HZXM");
    50      
    51         PeopleDao pd = new PeopleDaoImpI();
    52         System.out.println(HZXM);
    53        
    54         try {
    55             List<People> people=pd.selectall(HZXM,null,null,null);
    56             request.setAttribute("list", people);
    57             request.getRequestDispatcher("renkouliulaninfo.jsp").forward(request, response);
    58             System.out.println("人口查询成功!!!");
    59         }catch(Exception e){
    60             System.out.println("人口信息查询失败!!!");
    61             e.printStackTrace();
    62         }
    63     }
    64 
    65 }

    即可实现,人口信息,详细展示功能

  • 相关阅读:
    [Python] Marshmallow QuickStart
    [Python]Marshmallow 代码
    [python]Flask-migrate简单入门
    [数据库]Sqlite使用入门
    [Python] dict对象的keys()和values()返回的值,是否总是保证一一对应?
    【Weiss】【第03章】练习3.20:中缀表达式转后缀表达式
    【Weiss】【第03章】练习3.19:计算后缀表达式
    【Weiss】【第03章】练习3.18:检查平衡符号
    【Weiss】【第03章】练习3.17:懒惰删除
    【TIJ4】第六章全部习题【习题未完成】
  • 原文地址:https://www.cnblogs.com/2210633591zhang/p/14223011.html
Copyright © 2011-2022 走看看