JavaWeb项目-人口普查系统
项目需求:
开展第七次全国人口普查,将为编制“十四五”规划提供重要信息支持;推动实现人口与经济社会、资源环境协调发展,为深化供给侧结构性改革,推动经济高质量发展,建设现代化经济体系提供强有力的支持;人口普查还将为完善人口发展战略和政策体系,促进人口长期均衡发展提供重要信息支持。
主页面:
显示人口登记、修改人口信息、删除人口信息、查询人口信息,人口信息浏览五个子菜单。
人口登记页面:
①完成添加人口信息登记,基本信息和填报限制如下表所示
户 别 |
家庭户 集体户(单选框) |
住房类型 |
家庭住宅、集体住所、工作地住所、其他住宅、无住宅(单选框) |
本户现住房面积 |
XXXXX平方米(文本框,只能输入这个整数) |
本户现住房间数 |
XXXXX间(文本框,只能输入这个整数) |
户主姓名 |
XXXXX(文本框) |
身份证号码 |
XXXXXXXXXXXXXXXXXX(判断身份证位数18位并且只能录入数字、最后一位可以录入X) |
性别 |
男/女(单选框) |
民族 |
(文本框) |
受教育程度 |
研究生、大学本科、大学专科、高中、初中、小学、未上过学(下拉框实现) |
②点击“提交”按钮,保存成功则跳转到人口基本信息浏览界面,新录入的信息置顶显示。失败则提示错误信息,返回当前页面
修改人口信息页面:
输入户主姓名,显示其余信息,可对身份证号码、性别、民族、受教育程度进行修改。(身份证号码、性别、受教育程度必须符合录入要求);如果该名户主信息数据库不存在,则提示“该户主信息不存在”。(3分)
删除人口信息页面:
录入户主姓名,显示详细信息后,点击“删除”按钮,弹出提示框,提示“是否确认删除该户主信息”,确认后删除该信息。
浏览人口信息页面:
以列表形式显示人口基本信息,结果列表中显示姓名、性别,民族、受教育程度基本信息,点击姓名,可以跳转到个人详细信息。
查询人口信息页面:
要求可以根据姓名、性别、民族、受教育程度四种条件实现模糊查询,输出结果以列表形式显示,显示姓名、性别、民族、受教育程度基本信息,点击列表中的姓名,跳转到人口个人详细信息页面。
源代码:
Data.java
package test; import java.sql.*; import java.util.regex.Pattern; public class Data { private String hubie,housetype,houseS,home,name,id,sex,minzu,edu; public String gethubie() { return hubie; } public void sethubie(String hubie) { this.hubie = hubie; } public String gethousetype() { return housetype; } public void sethousetype(String housetype) { this.housetype = housetype; } public String gethouseS() { return houseS; } public void sethouseS(String houseS) { this.houseS = houseS; } public String gethome() { return home; } public void sethome(String home) { this.home =home ; } public String getname() { return name; } public void setname(String name) { this.name =name ; } public String getid() { return id; } public void setid(String id) { this.id = id; } public String getsex() { return sex; } public void setssex(String sex) { this.sex = sex; } public String getminzu() { return minzu; } public void setminzu(String minzu) { this.minzu = minzu; } public String getedu() { return edu; } public void setedu(String edu) { this.edu = edu; } //*********************************************************************** public Connection getConnection()//连接数据库 { try{ Class.forName("com.mysql.cj.jdbc.Driver"); //System.out.println("加载驱动成功"); }catch(ClassNotFoundException e) { e.printStackTrace(); } String user="root"; String password="123456"; String url = "jdbc:mysql://localhost:3306/ztest01?useSSL=false&serverTimezone=GMT&characterEncoding=utf-8&autoReconnect=true"; Connection con=null; try{ con=DriverManager.getConnection(url,user,password); //System.out.println("数据库连接成功"); }catch(SQLException e) { e.printStackTrace(); } return con; } //********************************************************************** //关闭方法 public void close (Connection con) { try{ if(con!=null) { con.close(); } }catch(SQLException e) { e.printStackTrace(); } } public void close (PreparedStatement preparedStatement) { try{ if(preparedStatement!=null) { preparedStatement.close(); } }catch(SQLException e) { e.printStackTrace(); } } public void close(ResultSet resultSet) { try{ if(resultSet!=null) { resultSet.close(); } }catch(SQLException e) { e.printStackTrace(); } } //****************************************************************** //增 public void adddata(String hubie,String housetype,String houseS,String home,String name,String id,String sex,String minzu,String edu) { Connection connection = getConnection(); PreparedStatement preparedStatement=null; try { //hubie,housetype,houseS,home,name,id,sex,minzu,edu; String sql = "insert into t0 (户别,住房类型,本户现住房面积,本户住房间数,户主姓名,身份证号,性别,民族,受教育程度) values (?,?,?,?,?,?,?,?,?)"; preparedStatement=connection.prepareStatement(sql); preparedStatement.setString(1,hubie); preparedStatement.setString(2,housetype); preparedStatement.setString(3,houseS); preparedStatement.setString(4,home); preparedStatement.setString(5,name); preparedStatement.setString(6,id); preparedStatement.setString(7,sex); preparedStatement.setString(8,minzu); preparedStatement.setString(9,edu); preparedStatement.executeUpdate(); //System.out.println("添加成功"); } catch (SQLException e) { e.printStackTrace(); }finally{ close(preparedStatement); close(connection); } } //删 public void deletedata(String id) { Connection connection = getConnection(); PreparedStatement preparedStatement=null; try { String sql = "delete from t0 where 身份证号 = ?"; preparedStatement=connection.prepareStatement(sql); preparedStatement.setString(1,id); preparedStatement.executeUpdate(); //System.out.println("删除成功"); } catch (SQLException e) { e.printStackTrace(); }finally{ close(preparedStatement); close(connection); } } //改 public void revisedata(String id0, String id, String sex, String minzu , String edu) { Connection connection = getConnection(); PreparedStatement preparedStatement=null; try { //身份证号码、性别、民族、受教育程度 String sql = "update t0 set 身份证号=?, 性别=?, 民族=?, 受教育程度=? where 身份证号=?"; preparedStatement=connection.prepareStatement(sql); preparedStatement.setString(1,id); preparedStatement.setString(2,sex); preparedStatement.setString(3,minzu); preparedStatement.setString(4,edu); preparedStatement.setString(5,id0); preparedStatement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); }finally{ close(preparedStatement); close(connection); } } //判断方法**************************************************************** //判空 public boolean isEmpty(String hubie,String housetype,String houseS,String home,String name,String id,String sex,String minzu,String edu) { if(hubie==null||housetype==null||houseS==""||home==""||name==""||id==""||sex==null||minzu==""||edu=="") return true; else return false; } //判整数-面积-房间数 public boolean isNumber(String str) { Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); return pattern.matcher(str).matches(); } //判断身份证号 public boolean isIdRight(String id) { if(id.length()==18) { for(int i=0;i<16;i++)//前17位 { char c=id.charAt(i); if(c=='0'||c=='1'||c=='2'||c=='3'||c=='4'||c=='5'||c=='6'||c=='7'||c=='8'||c=='9') {continue;} else {return false;} } char c=id.charAt(17);//第18位 if(c!='0'&&c!='1'&&c!='2'&&c!='3'&&c!='4'&&c!='5'&&c!='6'&&c!='7'&&c!='8'&&c!='9'&&c!='X') { //System.out.println("不是数字或者X"); return false; } else { //System.out.println("身份证号正确"); return true; } } else System.out.println("不是18位");return false; } //判重/判存在 public boolean isSame(String s) { Connection connection = getConnection(); PreparedStatement preparedStatement=null; ResultSet rs=null; try { String sql = "select * from t0"; preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); while(rs.next()){ if( s.equals(rs.getObject(6))||s.equals(rs.getObject(5)) ) return true; } //preparedStatement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); }finally{ close(rs); close(preparedStatement); close(connection); } return false; } //***************************************************************** public static void main(String[] args) { //Data a=new Data(); } }
主菜单menu.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>主菜单</title> </head> <body background="images\0.jpg"> <form action="addInput.jsp" method="get"> <p style="text-align:center;color:white;font-family:宋体; font-size:20px"> 人口普查系统 <br> 选择功能: <input type="button" value="信息登记" onclick="location.href='add.jsp'" /> <input type="button" value="信息删除" onclick="location.href='delete.jsp'" /> <input type="button" value="信息修改" onclick="location.href='revise.jsp'" /> <input type="button" value="查询信息" onclick="location.href='search.jsp'" /> <input type="button" value="浏览信息" onclick="location.href='show.jsp'" /> <br> </p> </form> </body> </html>
添加界面add.jsp
<%@page import="test.Data"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>登记</title> </head> <body> <form action="addjudge.jsp" method="get"> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 人口登记页面 <br> <br> <br>户别 <input type="radio" name="hubie" value="家庭户" />家庭户 <input type="radio" name="hubie" value="集体户" />集体户 <br> <br>住房类型 <input type="radio" name="housetype" value="家庭住宅" />家庭住宅 <input type="radio" name="housetype" value="集体住宅" />集体住宅 <input type="radio" name="housetype" value="工作地住所" />工作地住所 <input type="radio" name="housetype" value="其他住宅" />其他住宅 <input type="radio" name="housetype" value="无住宅" />无住宅 <br> <br> 本户现住房面积 <input type="text" name="houseS" size="4" /><br> <br> 本户现住房间数 <input type="text" name="home" size="2"/><br> <br> 户主姓名 <input type="text" name="name" size="4"/><br> <br> 身份证号码 <input type="text" name="id" /><br> <br>性别 <input type="radio" name="sex" value="男" />男 <input type="radio" name="sex" value="女" />女 <br> <br> 民族 <input type="text" name="minzu" /><br> <br> 受教育程度 <select name="edu"> <option selected="selected"></option> <option value="研究生">研究生</option> <option value="大学本科">大学本科</option> <option value="大学专科">大学专科</option> <option value="高中">高中</option> <option value="初中">初中</option> <option value="小学">小学</option> <option value="未上过学">未上过学</option> </select> <br><input type="submit" value="提交" /> <input type="reset" value="重置" /> <br> <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> </p> </form> </body> </html>
添加后台addjudge.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <jsp:useBean id="util" class="test.Data" scope="page" /> <% //hubie,housetype,houseS,home,name,id,sex,minzu,edu; String hubie=(String)request.getParameter("hubie"); String housetype=(String)request.getParameter("housetype"); String houseS=(String)request.getParameter("houseS"); String home=(String)request.getParameter("home"); String name=(String)request.getParameter("name"); String id=(String)request.getParameter("id"); String sex=(String)request.getParameter("sex"); String minzu=(String)request.getParameter("minzu"); String edu=(String)request.getParameter("edu"); if(util.isEmpty(hubie,housetype,houseS,home,name,id,sex,minzu,edu)){ out.print("<script language='javaScript'> alert('输入为空');window.history.back(-1);</script>"); } else if(!util.isNumber(houseS)) { out.print("<script language='javaScript'> alert('现住房面积应该为整数');window.history.back(-1);</script>"); } else if(!util.isNumber(home)) { out.print("<script language='javaScript'> alert('现住房间数应该为整数');window.history.back(-1);</script>"); } else if(!util.isIdRight(id)) { out.print("<script language='javaScript'> alert('身份证号码不正确');window.history.back(-1);</script>"); } else if(util.isSame(id)) { out.print("<script language='javaScript'> alert('该住户已经登记过了');window.history.back(-1);</script>"); } else{ util.adddata(hubie, housetype, houseS, home, name, id, sex, minzu, edu); out.print("<script language='javaScript'> alert('添加成功');</script>"); response.setHeader("refresh", "0;url=show.jsp"); } %> </body> </html>
删除界面delete.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>删除</title> </head> <body> <form action="deletejudge.jsp" method="get"> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 信息删除页面 <br> 要删除信息的户主姓名: <input type="text" name="name" /> <br> <br><input type="submit" value="确定" /> <input type="reset" value="重置" /> <br> <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> </p> </form> </body> </html>
删除后台1
deletejudge.jsp
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <jsp:useBean id="util" class="test.Data" scope="page" /> <% String name=(String)request.getParameter("name"); if(name==""){ out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>"); } else if(!util.isSame(name)) { out.print("<script language='javaScript'> alert('该住户不存在'); window.history.back(-1); </script>"); } else{ %> <table border="1"style="text-align:center;"> <tr> <td align="center" width=6%>户别</td> <td align="center" width=8%>住房类型</td> <td align="center" width=10%>本户现住房面积</td> <td align="center" width=10%>本户现住房间数</td> <td align="center" width=6%>姓名</td> <td align="center" width=18%>身份证号码</td> <td align="center" width=3%>性别</td> <td align="center" width=10>民族</td> <td align="center" width=10%>受教育程度</td> <td align="center" width=3%>删除</td> </tr> <% Connection connection = util.getConnection(); PreparedStatement preparedStatement=null; ResultSet rs=null; try { String sql = "select * from t0"; preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); while(rs.next()){ if(name.equals(rs.getObject(5))) { %> <tr> <td align="center"><%=rs.getObject(1) %></td> <td align="center"><%=rs.getObject(2) %></td> <td align="center"><%=rs.getObject(3) %></td> <td align="center"><%=rs.getObject(4) %></td> <td align="center"><%=rs.getObject(5) %></td> <td align="center"><%=rs.getObject(6) %></td> <td align="center"><%=rs.getObject(7) %></td> <td align="center"><%=rs.getObject(8) %></td> <td align="center"><%=rs.getObject(9) %></td> <td align="center"><a style="color:blue" href='deletejudge2.jsp?id=<%=rs.getObject(6) %>' onclick="javascript:return del()">删除</a> </td> </tr> <% } } } catch (SQLException e) { e.printStackTrace(); }finally{ util.close(rs); util.close(preparedStatement); util.close(connection); } %> </table> <% } %> <script> function del(){ var r = confirm("确定要删除吗?") if (r == true) { return true; } else { return false; } } </script> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> </p> </body> </html>
删除后台2
deletejudge2.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <input type="button" onclick="openResult()" value="删除"/> <jsp:useBean id="util" class="test.Data" scope="page" /> <% String id=(String)request.getParameter("id"); util.deletedata(id); out.print("<script language='javaScript'> alert('删除成功');</script>"); response.setHeader("refresh", "0;url=delete.jsp"); %> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> </p> </body> </html>
修改界面revise.jsp
<%@page import="test.Data"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>登记</title> </head> <body> <form action="revisejudge.jsp" method="get"> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> <br> 输入要修改的户主姓名 <input type="text" name="name" /><br> <br><input type="submit" value="提交" /> <input type="reset" value="重置" /> <br> <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> </p> </form> </body> </html>
修改后台1
revisejudge.jsp
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>登记</title> </head> <body> <jsp:useBean id="util" class="test.Data" scope="page" /> <% String name=(String)request.getParameter("name"); if(name==""){ out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>"); } else if(!util.isSame(name)) { out.print("<script language='javaScript'> alert('该住户不存在'); window.history.back(-1); </script>"); } else{ %> <table border="1"style="text-align:center;"> <tr> <td align="center" width=6%>户别</td> <td align="center" width=8%>住房类型</td> <td align="center" width=10%>本户现住房面积</td> <td align="center" width=10%>本户现住房间数</td> <td align="center" width=6%>姓名</td> <td align="center" width=18%>身份证号码</td> <td align="center" width=3%>性别</td> <td align="center" width=10>民族</td> <td align="center" width=10%>受教育程度</td> <td align="center" width=3%>修改</td> </tr> <% Connection connection = util.getConnection(); PreparedStatement preparedStatement=null; ResultSet rs=null; try { String sql = "select * from t0"; preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); while(rs.next()){ if(name.equals(rs.getObject(5))) { %> <tr> <td align="center"><%=rs.getObject(1) %></td> <td align="center"><%=rs.getObject(2) %></td> <td align="center"><%=rs.getObject(3) %></td> <td align="center"><%=rs.getObject(4) %></td> <td align="center"><%=rs.getObject(5) %></td> <td align="center"><%=rs.getObject(6) %></td> <td align="center"><%=rs.getObject(7) %></td> <td align="center"><%=rs.getObject(8) %></td> <td align="center"><%=rs.getObject(9) %></td> <td align="center"><a style="color:blue" href='revisejudge2.jsp?id0=<%=rs.getObject(6) %>'>修改</a> </td> </tr> <% } } } catch (SQLException e) { e.printStackTrace(); }finally{ util.close(rs); util.close(preparedStatement); util.close(connection); } %> </table> <% } %> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> </p> </body> </html>
修改后台2
revisejudge2.jsp
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <jsp:useBean id="util" class="test.Data" scope="page" /> <% String id0=(String)request.getParameter("id0"); session.setAttribute("id0",id0); %> <table border="1"style="text-align:center;"> <tr> <td align="center" width=6%>户别</td> <td align="center" width=8%>住房类型</td> <td align="center" width=10%>本户现住房面积</td> <td align="center" width=10%>本户现住房间数</td> <td align="center" width=6%>姓名</td> <td align="center" width=18%>身份证号码</td> <td align="center" width=3%>性别</td> <td align="center" width=10>民族</td> <td align="center" width=10%>受教育程度</td> </tr> <% Connection connection = util.getConnection(); PreparedStatement preparedStatement=null; ResultSet rs=null; try { String sql = "select * from t0"; preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); while(rs.next()){ if(id0.equals(rs.getObject(6))) { %> <tr> <td align="center"><%=rs.getObject(1) %></td> <td align="center"><%=rs.getObject(2) %></td> <td align="center"><%=rs.getObject(3) %></td> <td align="center"><%=rs.getObject(4) %></td> <td align="center"><%=rs.getObject(5) %></td> <td align="center"><%=rs.getObject(6) %></td> <td align="center"><%=rs.getObject(7) %></td> <td align="center"><%=rs.getObject(8) %></td> <td align="center"><%=rs.getObject(9) %></td> </tr> <% } } } catch (SQLException e) { e.printStackTrace(); }finally{ util.close(rs); util.close(preparedStatement); util.close(connection); } %> </table> <form action="revisejudge3.jsp" method="get"> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> <br> <br> 修改信息 <br> 身份证号码 <input type="text" name="id" /><br> <br>性别 <input type="radio" name="sex" value="男" />男 <input type="radio" name="sex" value="女" />女 <br> <br> 民族 <input type="text" name="minzu" /><br> <br> 受教育程度 <select name="edu"> <option selected="selected"></option> <option value="研究生">研究生</option> <option value="大学本科">大学本科</option> <option value="大学专科">大学专科</option> <option value="高中">高中</option> <option value="初中">初中</option> <option value="小学">小学</option> <option value="未上过学">未上过学</option> </select> <br><input type="submit" value="提交" /> <input type="reset" value="重置" /> <br> <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> </p> </form> </body> </html>
修改后台3
revisejudge3.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <jsp:useBean id="util" class="test.Data" scope="page" /> <% String id0=(String)session.getAttribute("id0"); String id=(String)request.getParameter("id"); String sex=(String)request.getParameter("sex"); String minzu=(String)request.getParameter("minzu"); String edu=(String)request.getParameter("edu"); if(id==""||sex==""||minzu==""||edu=="") { out.print("<script language='javaScript'> alert('输入为空');window.history.back(-1);</script>"); } else if(!util.isIdRight(id)) { out.print("<script language='javaScript'> alert('身份证号码不正确');window.history.back(-1);</script>"); } else { util.revisedata(id0,id, sex, minzu, edu); out.print("<script language='javaScript'> alert('修改成功');</script>"); response.setHeader("refresh", "0;url=revise.jsp"); } %> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> </p> </body> </html>
查询界面search.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>查询</title> </head> <body> <form action="searchjudge.jsp" method="get"> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> 输入要查询信息的姓名/性别/民族/受教育程度(支持模糊查询): <br> <input type="text" name="data" /> <br> <br><input type="submit" value="提交" /> <input type="reset" value="重置" /> <br> <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> </p> </form> </body> </html>
查询后台searchjudge.jsp
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>查询</title> </head> <body style="text-align:center"> 查询结果 <p> <jsp:useBean id="util" class="test.Data" scope="page" /> <% String data=(String)request.getParameter("data"); if(data==""){ out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>"); } else { %> <table border="1"style="text-align:center;"> <tr> <td align="center" width=6%>姓名</td> <td align="center" width=3%>性别</td> <td align="center" width=10>民族</td> <td align="center" width=10%>受教育程度</td> </tr> <% int i=0; Connection connection = util.getConnection(); PreparedStatement preparedStatement=null; ResultSet rs=null; try { String sql= " select * from t0 where 户主姓名 like ? or 性别 like ? or 民族 like ? or 受教育程度 like ? "; preparedStatement=connection.prepareStatement(sql); preparedStatement.setString(1,"%"+data+"%"); preparedStatement.setString(2,"%"+data+"%"); preparedStatement.setString(3,"%"+data+"%"); preparedStatement.setString(4,"%"+data+"%"); rs=preparedStatement.executeQuery(); while(rs.next()) { i++; %> <tr> <td align="center"><a style="color:blue" href='searchshowall.jsp?id=<%=rs.getObject(6) %>'><%=rs.getObject(5) %></a> </td> <td align="center"><%=rs.getObject(7) %></td> <td align="center"><%=rs.getObject(8) %></td> <td align="center"><%=rs.getObject(9) %></td> </tr> <% } if(i==0) { out.print("<script language='javaScript'> alert('没有查询到有关信息'); window.history.back(-1); </script>"); } } catch (SQLException e) { e.printStackTrace(); }finally{ util.close(rs); util.close(preparedStatement); util.close(connection); } } %> </table> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> <br> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> </p> </body> </html>
查询显示详细信息searchshowall.jsp
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>详细信息</title> </head> <body> <jsp:useBean id="util" class="test.Data" scope="page" /> <% String id = (String)request.getParameter("id"); Connection connection = util.getConnection(); PreparedStatement preparedStatement=null; ResultSet rs=null; try { String sql = "select * from t0"; preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); while(rs.next()){ if(id.equals(rs.getObject(6))) { %> <table border="1"style="text-align:center;"> <tr> <td align="center" width=6%>户别</td> <td align="center" width=8%>住房类型</td> <td align="center" width=10%>本户现住房面积</td> <td align="center" width=10%>本户现住房间数</td> <td align="center" width=6%>姓名</td> <td align="center" width=18%>身份证号码</td> <td align="center" width=3%>性别</td> <td align="center" width=10>民族</td> <td align="center" width=10%>受教育程度</td> </tr> <tr> <td align="center"><%=rs.getObject(1) %></td> <td align="center"><%=rs.getObject(2) %></td> <td align="center"><%=rs.getObject(3) %></td> <td align="center"><%=rs.getObject(4) %></td> <td align="center"><%=rs.getObject(5) %></td> <td align="center"><%=rs.getObject(6) %></td> <td align="center"><%=rs.getObject(7) %></td> <td align="center"><%=rs.getObject(8) %></td> <td align="center"><%=rs.getObject(9) %></td> </tr> <% } } } catch (SQLException e) { e.printStackTrace(); }finally{ util.close(rs); util.close(preparedStatement); util.close(connection); } %> </table> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> <input type="button" name="back" onclick="javascript:window.history.back(-1);" value=返回上一页> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> </p> </body> </html>
浏览信息show.jsp
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>浏览信息</title> </head> <body> <jsp:useBean id="util" class="test.Data" scope="page" /> <table border="1"style="text-align:center;"> <tr> <td align="center" width=6%>户别</td> <td align="center" width=8%>住房类型</td> <td align="center" width=10%>本户现住房面积</td> <td align="center" width=10%>本户现住房间数</td> <td align="center" width=6%>姓名</td> <td align="center" width=18%>身份证号码</td> <td align="center" width=3%>性别</td> <td align="center" width=10>民族</td> <td align="center" width=10%>受教育程度</td> </tr> <% Connection connection = util.getConnection(); PreparedStatement preparedStatement=null; ResultSet rs=null; try { String sql = "select * from t0"; preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); while(rs.next()){ %> <tr> <td align="center"><%=rs.getObject(1) %></td> <td align="center"><%=rs.getObject(2) %></td> <td align="center"><%=rs.getObject(3) %></td> <td align="center"><%=rs.getObject(4) %></td> <td align="center"><%=rs.getObject(5) %></td> <td align="center"><%=rs.getObject(6) %></td> <td align="center"><%=rs.getObject(7) %></td> <td align="center"><%=rs.getObject(8) %></td> <td align="center"><%=rs.getObject(9) %></td> </tr> <% } } catch (SQLException e) { e.printStackTrace(); }finally{ util.close(rs); util.close(preparedStatement); util.close(connection); } %> </table> <p style="text-align:center;color: black; font-family: 宋体; font-size: 20px"> <input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br> </p> </body> </html>