第七次全国人口普查登记系统-19级期中考试题

 

第七次全国人口普查登记(20分)

1、项目需求:

开展第七次全国人口普查,将为编制“十四五”规划提供重要信息支持;推动实现人口与经济社会、资源环境协调发展,为深化供给侧结构性改革,推动经济高质量发展,建设现代化经济体系提供强有力的支持;人口普查还将为完善人口发展战略和政策体系,促进人口长期均衡发展提供重要信息支持。

2.系统要求与功能设计

2.1 页面功能要求

1)能够在Tomcat服务器中正确部署,并通过浏览器查看;(1分)

2)网站页面整体风格统一;

 

1 人口普查系统功能结构图

3)主页面:要求显示人口登记、修改人口信息、删除人口信息、查询人口信息,人口信息浏览五个子菜单。(1分)

4)人口登记页面:(6分)

①完成添加人口信息登记,基本信息和填报限制如下表所示

 

 

家庭户 集体户(单选框)

住房类型

家庭住宅、集体住所、工作地住所、其他住宅、无住宅(单选框)

本户现住房面积

XXXXX平方米(文本框,只能输入这个整数)

本户现住房间数

XXXXX间(文本框,只能输入这个整数)

户主姓名

XXXXX(文本框)

身份证号码

XXXXXXXXXXXXXXXXXX(判断身份证位数13位并且只能录入数字、最后一位可以录入X)

性别

/女(单选框)

民族

(文本框)

受教育程度

研究生、大学本科、大学专科、高中、初中、小学、未上过学(下拉框实现)

 

点击“提交”按钮,保存成功则跳转到人口基本信息浏览界面,新录入的信息置顶显示。失败则提示错误信息,返回当前页面

评分标准:

①完成人口登记页面(未完成0分,完成1分)

②保存人口信息入库(未完成0分,完成1分)

③户别、住房类别、性别实现一个单选框录入0.5分,全部实现1分。(未完成0分,完成一个0.5,全部完成1分)

④本户现住房面积或本户现住房间数实现整数判断(未完成0分,完成0.5分)

⑤判断身份证按照要求录入,实现位数和数字录入判断0.5分,实现最后一位可以输入数字或X判断0.5分。(1分)

⑥受教育程度下拉框录入(未完成0分,完成0.5分)

⑦提交后页面跳转功能;(未完成0分,完成1分)

5)修改人口信息页面:3分)

输入户主姓名,显示其余信息,可对身份证号码、性别、民族、受教育程度进行修改。(身份证号码、性别、受教育程度必须符合录入要求);如果该名户主信息数据库不存在,则提示“该户主信息不存在”。(3分)

评分标准:

①完成修改户主个人信息页面(未完成0分,完成0.5分)

② 实现数据库中信息更新(未完成0分,完成1分)

③修改信息判断是否符合要求。(未完成0分,完成0.5分)

④输入姓名,显示其余信息,若该信息不存在,提示错误信息;(未完成0分,完成1分)

6)删除人口信息页面:录入户主姓名,显示详细信息后,点击“删除”按钮,弹出提示框,提示“是否确认删除该户主信息”,确认后删除该信息。(1分)

评分标准:

①输入户主姓名可显示其余信息。(未完成0分,完成0.5分)

②对应删除数据库中信息(未完成0分,完成0.5分)

7)浏览人口信息页面:(2分)

以列表形式显示人口基本信息,结果列表中显示姓名、性别,民族、受教育程度基本信息,点击姓名,可以跳转到个人详细信息。

评分标准:

①实现以列表形式显示人口基本信息,结果列表中显示姓名、性别,民族、受教育程度基本信息(未完成0分,完成1分)

②实现跳转个人详细信息页面。(未完成0分,完成1分)

8)查询人口信息页面:(3分)

要求可以根据人口姓名、性别、民族、受教育程度四种条件实现模糊查询,输出结果以列表形式显示,显示人口姓名、性别、民族、受教育程度基本信息,点击列表中的姓名,跳转到人口个人详细信息页面。

评分标准:

①缺少一种查询条件扣除1分。(未完成0分,完成3分)

2.2 功能要求

1)设计出合理的数据库和数据表,要求使用mysql、sqlserver、oracle三种数据库中一种(1分)

2)使用Serverlet实现页面交互(1分)。

3)使用Java Bean封装数据库连接操作(1分。)

 

相关配置 

 

 

项目结构

数据库

 

 

 

 

bean.java

package Bean;

public class bean
{
private String hubie;
private String housetype;
private String houseS;
private String home;
private String name;
private String id;
private String sex;
private String minzu;
private String 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 setSex(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;
}
}

dao.java

package Dao;

import Bean.bean;
import Util.util;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;



public class dao
{
public void adddata(bean bean)//增
{
Connection connection=util.getConnection();
PreparedStatement preparedStatement=null;
try
{
String sql="insert into t0(户别,住房类型,本户现住房面积,本户住房间数,户主姓名,身份证号,性别,民族,受教育程度) values(?,?,?,?,?,?,?,?,?)";
preparedStatement =connection.prepareStatement(sql);
preparedStatement.setString(1,bean.getHubie());
preparedStatement.setString(2,bean.getHousetype());
preparedStatement.setString(3,bean.getHouseS());
preparedStatement.setString(4,bean.getHome());
preparedStatement.setString(5,bean.getName());
preparedStatement.setString(6,bean.getId());
preparedStatement.setString(7,bean.getSex());
preparedStatement.setString(8,bean.getMinzu());
preparedStatement.setString(9,bean.getEdu());
preparedStatement.executeUpdate();
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
util.close(preparedStatement);
util.close(connection);
}

}
public void deletedata(String id)
{
bean bean=new bean();
Connection connection = util.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{
util.close(preparedStatement);
util.close(connection);
}
}
public void changedata(String idn, String id, String sex, String minzu , String edu)
{
Connection connection = util.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,idn);
preparedStatement.executeUpdate();

} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(preparedStatement);
util.close(connection);
}
}

}

util.java
package Util;

import java.sql.*;

public class util
{
public static Connection getConnection()//连接数据库
{
try{
Class.forName("com.mysql.cj.jdbc.Driver");
//System.out.println("加载驱动成功");
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}
String user="root";
String password="Mendy030628";
String url = "jdbc:mysql://localhost:3306/db1?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 static void close (Connection con)
{
try{
if(con!=null)
{
con.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public static void close(PreparedStatement preparedStatement)
{
try{
if(preparedStatement!=null)
{
preparedStatement.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public static void close(ResultSet resultSet)
{
try{
if(resultSet!=null)
{
resultSet.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public static void main(String[] args) throws SQLException {
}
}

jsp部分
add.jsp
<%--
Created by IntelliJ IDEA.
User: mendianyu
Date: 2022/10/22
Time: 11:51
To change this template use File | Settings | File Templates.
--%>
<%--<%@page import="test.Data"%>--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>人口信息登记</title>
</head>
<body>
<center><h3>人口信息登记</h3></center>
<form action="addjudge.jsp" method="get">
<p style="text-align: center">

户别:
<input type="radio" name="hubie" value="家庭户"> 家庭户
<input type="radio" name="hubie" value="集体户"> 集体户
<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>
本户现住房面积:
<input type="text" name="houseS" oninput="this.value = this.value.replace(/[^0-9]/g, '');">
<br>
本户现房间数:
<input type="text" name="home" oninput="this.value = this.value.replace(/[^0-9]/g, '');">
<br>
户主姓名:
<input type="text" name="name">
<br>
身份证号码:
<input type="text" name="id" maxlength="18" oninput="this.value = this.value.replace(/[^0-9,x]/g, '');">
<br>
性别:
<input type="radio" name="sex" value="男">男
<input type="radio" name="sex" value="女">女
<br>
民族:
<input type="text" name="minzu">
<br>
受教育程度:
<select name="edu">
<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>
<a href="menu.jsp">返回主页</a>
</p>
</form>
</body>
</html>
addjudge.jsp
<%--
Created by IntelliJ IDEA.
User: mendianyu
Date: 2022/10/22
Time: 13:03
To change this template use File | Settings | File Templates.
--%>
<%@ page import="Bean.bean" %>
<%@ page import="Dao.dao" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<%
String hubie=request.getParameter("hubie");
String housetype=request.getParameter("housetype");
String houseS=request.getParameter("houseS");
String home=request.getParameter("home");
String name=request.getParameter("name");
String id=request.getParameter("id");
String sex=request.getParameter("sex");
String minzu=request.getParameter("minzu");
String edu=request.getParameter("edu");

bean bean=new bean();
bean.setHubie(hubie);
bean.setHousetype(housetype);
bean.setHouseS(houseS);
bean.setHome(home);
bean.setName(name);
bean.setId(id);
bean.setSex(sex);
bean.setMinzu(minzu);
bean.setEdu(edu);

dao dao=new dao();
dao.adddata(bean);
out.print("<script language='javaScript'> alert('添加成功');</script>");
response.setHeader("refresh", "0;url=list.jsp");
%>
</body>
</html>
change.jsp
<%--
Created by IntelliJ IDEA.
User: mendianyu
Date: 2022/10/22
Time: 13:38
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
<title>信息修改</title>
</head>
<body>
<form action="changejudge1.jsp" method="get">
输入要修改信息的户主的姓名
<br>
<input type="text" name="name">
<br>
<input type="submit" value="提交">
<input type="reset" value="重置">
<br>
<input type="button" value="返回主菜单" onclick="location.href='menu.jsp'">

</form>
</body>
</html>

changejudge1.jsp
<%--
Created by IntelliJ IDEA.
User: wuwang
Date: 2022/10/21
Time: 12:15
To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="Util.util" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登记</title>
</head>
<body>

<%
String name=(String)request.getParameter("name");
if(name=="")
{
out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>");
}
else{
%>
<table border="1" cellspacing="0" 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>
<%
int i=0;
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)))
{
i++;
%>
<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='changejudge2.jsp?idn=<%=rs.getObject(6) %>'>修改</a> </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>

changejudge2.jsp

<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="Util.util" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<%

String idn=(String)request.getParameter("idn");
session.setAttribute("idn",idn);
%>
<table border="1"cellspacing="0" 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(idn.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="changejudge3.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>

changejudge3.jsp
<%@ page import="Dao.dao" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>

<%

String idn=(String)session.getAttribute("idn");
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
{
dao dao=new dao();
dao.changedata(idn,id, sex, minzu, edu);
out.print("<script language='javaScript'> alert('修改成功');</script>");
response.setHeader("refresh", "0;url=change.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>

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="deletejudge1.jsp" method="get">
<p style="text-align:center;">
信息删除页面
要删除信息的户主姓名: <input type="text" name="name" >
<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>

deletejudge1.jsp
<%@ page import="java.sql.Connection" %>
<%@ page import="Util.util" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>

<%@ 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</title>
</head>
<body>
<%
String name=request.getParameter("name");
if(name=="")
{
out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>");
}
else{
%>
<table border="1" cellspacing="0">
<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>

deletejudge2.jsp
<%@ page import="Dao.dao" %>
<%@ 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="删除"/>

<%
dao dao=new dao();
String id=(String)request.getParameter("id");
dao.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>

list.jsp
<%--
Created by IntelliJ IDEA.
User: wuwang
Date: 2022/10/21
Time: 12:18
To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="Util.util" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>浏览信息</title>
</head>
<body>


<table border="1" cellspacing="0" style="text-align:center;">
<tr>

<td align="center" width=6%>姓名</td>
<td align="center" width=3%>性别</td>
<td align="center" width=5%>民族</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"><a href='listall.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>
<%
}
} 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>

listall.jsp
<%--
Created by IntelliJ IDEA.
User: wuwang
Date: 2022/10/21
Time: 12:18
To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="Util.util" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>详细信息</title>
</head>
<body>

<%
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"cellspacing="0"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>

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>


<form action="#" method="get">
<p style="text-align:center;font-size:20px" >

<input type="button" value="信息登记" onclick="location.href='add.jsp'" /><br>
<input type="button" value="信息删除" onclick="location.href='delete.jsp'" /><br>
<input type="button" value="信息修改" onclick="location.href='change.jsp'" /><br>
<input type="button" value="查询信息" onclick="location.href='search.jsp'" /><br>
<input type="button" value="浏览信息" onclick="location.href='list.jsp'" /><br>
<br>
</p>

</form>


</html>

search.jsp
<%--
Created by IntelliJ IDEA.
User: mendianyu
Date: 2022/10/22
Time: 13:39
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
<meta charset="UTF-8">
<title>信息查询</title>
</head>
<body>
<form action="searchjudge.jsp" method="get">
输入要查询的信息的姓名/性别/民族/受教育程度(支持模糊查询)
<br>
<input type="text" name="data">
<br>
<input type="submit" value="提交" >
<input type="reset" value="重置" >
<br>
<input type="button" value="返回菜单" onclick="location.href='menu.jsp'">
<br>
</form>
</body>
</html>

searchall.jsp

<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="Util.util" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>浏览信息</title>
</head>
<body>


<table border="1" cellspacing="0" 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=5%>民族</td>
<td align="center" width=10%>受教育程度</td>
</tr>
<%
String id=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)))
{
%>
<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>

searchjudge.jsp
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="Util.util" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
String data=(String)request.getParameter("data");
if(data=="")
{
out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>");
}
else
{
%>
<table border="1" cellspacing="0">
<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 href='searchall.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>


 
 
 
 
 
 
 
 
 
 
 



 



 

 



 

 



 

posted @ 2022-10-25 11:37  Men!  阅读(82)  评论(0编辑  收藏  举报