第七次全国人口普查登记系统

第七次全国人口普查登记(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分。)

 

1.Dao部分

1.添加
import com.pojo.Person;
import com.util.jdbcUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class AddDao {
    public int add(Person person) throws Exception {
        Connection connection = jdbcUtil.getConnection();
        String sql = "insert into person(hu_bie, idc,  name,  jiao_yu, lei_xing, mian_ji, min_zu,  shu_mu, sex) value(?,?,?,?,?,?,?,?,?)";

        PreparedStatement pstmt = null;
        pstmt = connection.prepareStatement(sql);

       // pstmt.setInt(1,  person.getId());
        pstmt.setString(1,  person.getHu_bie());
        pstmt.setString(2,  person.getIdc());
        pstmt.setString(3,  person.getName());
        pstmt.setString(4,  person.getJiao_yu());
        pstmt.setString(5,  person.getLei_xing());
        pstmt.setString(6,  person.getMian_ji());
        pstmt.setString(7,  person.getMin_zu());
        pstmt.setString(8,  person.getShu_mu());
        pstmt.setString(9,  person.getSex());


        int count =pstmt.executeUpdate();
        jdbcUtil.close(connection);
        jdbcUtil.close(pstmt);

        return count;
    }
}
2.删除
import com.pojo.Person;
import com.util.jdbcUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class DeleteDao {
    public int delete(Person person) throws Exception {
        Connection connection = jdbcUtil.getConnection();
        String sql = "delete from person where id = ?";

        PreparedStatement pstmt = null;
        pstmt = connection.prepareStatement(sql);

        pstmt.setInt(1,  person.getId());

        int count =pstmt.executeUpdate();
        jdbcUtil.close(connection);
        jdbcUtil.close(pstmt);

        return count;
    }
}
3.查询所有

import com.pojo.Person;
import com.sun.corba.se.impl.orb.PropertyOnlyDataCollector;
import com.util.jdbcUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class SeleteDao {

    public List<Person> selectall() throws Exception {
        Connection connection = jdbcUtil.getConnection();

        String sql = "select * from person";

        PreparedStatement pstmt = null;
        pstmt = connection.prepareStatement(sql);

        ResultSet rs = pstmt.executeQuery();

        Person person = null;
        List<Person> list = new ArrayList<>();

        while (rs.next()) {
            int id = Integer.parseInt(rs.getString("id"));
            String name2 = rs.getString("name");
            String min_zu2 = rs.getString("min_zu");
            String jiao_yu2 = rs.getString("jiao_yu");
            String sex2 = rs.getString("sex");
            String idc2 = rs.getString("idc");
            String hu_bie2 = rs.getString("hu_bie");
            String zhu_fang_lei_bie2 = rs.getString("lei_xing");
            String S2 =  rs.getString("shu_mu");
            String N2 =  rs.getString("mian_ji");
            person = new Person(id,hu_bie2,idc2,name2,jiao_yu2,zhu_fang_lei_bie2,N2,min_zu2,S2,sex2);
            list.add(person);
        }
        jdbcUtil.close(connection);
        jdbcUtil.close(pstmt);
        rs.close();
        return list;
    }

4.查询一个人
public Person select_one(int id) throws Exception { Connection connection = jdbcUtil.getConnection(); String sql = "select * from person where id =?"; Person person = null; PreparedStatement pstmt = null; pstmt = connection.prepareStatement(sql); pstmt.setInt(1, id); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { int iD = Integer.parseInt(rs.getString("id")); String name2 = rs.getString("name"); String min_zu2 = rs.getString("min_zu"); String jiao_yu2 = rs.getString("jiao_yu"); String sex2 = rs.getString("sex"); String idc2 = rs.getString("idc"); String hu_bie2 = rs.getString("hu_bie"); String zhu_fang_lei_bie2 = rs.getString("lei_xing"); String S2 = rs.getString("shu_mu"); String N2 = rs.getString("mian_ji"); person = new Person(iD,hu_bie2,idc2,name2,jiao_yu2,zhu_fang_lei_bie2,N2,min_zu2,S2,sex2); } jdbcUtil.close(connection); jdbcUtil.close(pstmt); rs.close(); return person; }
//按照姓名,模糊查询
public List<Person> getbyname(String name) throws Exception {
Connection connection = jdbcUtil.getConnection();

String sql = "select * from person where name like ?";

PreparedStatement pstmt = null;
pstmt = connection.prepareStatement(sql);
pstmt.setString(1, name);
ResultSet rs = pstmt.executeQuery();

Person person = null;
List<Person> list = new ArrayList<>();

while (rs.next()) {
int id = Integer.parseInt(rs.getString("id"));
String name2 = rs.getString("name");
String min_zu2 = rs.getString("min_zu");
String jiao_yu2 = rs.getString("jiao_yu");
String sex2 = rs.getString("sex");
String idc2 = rs.getString("idc");
String hu_bie2 = rs.getString("hu_bie");
String zhu_fang_lei_bie2 = rs.getString("lei_xing");
String S2 = rs.getString("shu_mu");
String N2 = rs.getString("mian_ji");
person = new Person(id,hu_bie2,idc2,name2,jiao_yu2,zhu_fang_lei_bie2,N2,min_zu2,S2,sex2);
list.add(person);
}
jdbcUtil.close(connection);
jdbcUtil.close(pstmt);
rs.close();
return list;
}

//返回模糊查询是否查询成功
public int getbyname_if(String name) throws Exception {
Connection connection = jdbcUtil.getConnection();

String sql = "select * from person where name like ?";

PreparedStatement pstmt = null;
pstmt = connection.prepareStatement(sql);
pstmt.setString(1, name);
int count = 0;
ResultSet rs = pstmt.executeQuery();
if(rs.next())
{
count++;
}
jdbcUtil.close(connection);
jdbcUtil.close(pstmt);
jdbcUtil.close(rs);
return count;
}
}
5.修改
import com.pojo.Person;
import com.util.jdbcUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class UpdataDao {
    public int updata(Person person) throws Exception {
        Connection connection = jdbcUtil.getConnection();
        String sql = "update person\n"+
                "set  hu_bie  = ?,\n "+
                 "idc  = ?,\n " +
                 "name = ?,\n"+
                 "jiao_yu = ?,\n"+
                 "lei_xing = ?,\n"+
                 "mian_ji = ?,\n"+
                 "min_zu = ?,\n"+
                 "shu_mu = ?,\n"+
                 "sex = ?" +
                "where id = ?";

        PreparedStatement pstmt = null;
        pstmt = connection.prepareStatement(sql);

        pstmt.setString(1,  person.getHu_bie());
        pstmt.setString(2,  person.getIdc());
        pstmt.setString(3,  person.getName());
        pstmt.setString(4,  person.getJiao_yu());
        pstmt.setString(5,  person.getLei_xing());
        pstmt.setString(6,  person.getMian_ji());
        pstmt.setString(7,  person.getMin_zu());
        pstmt.setString(8,  person.getShu_mu());
        pstmt.setString(9,  person.getSex());
        pstmt.setInt(10,  person.getId());

        int count =pstmt.executeUpdate();

        jdbcUtil.close(connection);
        jdbcUtil.close(pstmt);

        return count;
    }
}

二、JavaBen

public class Person {
    private int id;
    private String hu_bie;
    private String idc;
    private String name;
    private String jiao_yu;
    private String lei_xing;
    private String mian_ji;
    private String min_zu;
    private String shu_mu;
    private String sex;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIdc() {
        return idc;
    }

    public void setIdc(String idc) {
        this.idc = idc;
    }

    public String getMin_zu() {
        return min_zu;
    }

    public void setMin_zu(String min_zu) {
        this.min_zu = min_zu;
    }

    public String getJiao_yu() {
        return jiao_yu;
    }

    public void setJiao_yu(String jiao_yu) {
        this.jiao_yu = jiao_yu;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getHu_bie() {
        return hu_bie;
    }

    public void setHu_bie(String hu_bie) {
        this.hu_bie = hu_bie;
    }

    public String getLei_xing() {
        return lei_xing;
    }

    public void setLei_xing(String lei_xing) {
        this.lei_xing = lei_xing;
    }

    public String getMian_ji() {
        return mian_ji;
    }

    public void setMian_ji(String mian_ji) {
        this.mian_ji = mian_ji;
    }

    public String getShu_mu() {
        return shu_mu;
    }

    public void setShu_mu(String shu_mu) {
        this.shu_mu = shu_mu;
    }

    @Override
    public String toString() {
        return "person{" +
                "name='" + name + '\'' +
                ", idc='" + idc + '\'' +
                ", min_zu='" + min_zu + '\'' +
                ", jiao_yu='" + jiao_yu + '\'' +
                ", sex='" + sex + '\'' +
                ", hu_bie='" + hu_bie + '\'' +
                ", lei_xing='" + lei_xing + '\'' +
                ", mian_ji='" + mian_ji + '\'' +
                ", shu_mu='" + shu_mu + '\'' +
                '}';
    }

//    public Person(int id ,String name, String idc, String min_zu, String jiao_yu, String sex, String hu_bie, String lei_xing, String mian_ji, String shu_mu) {
//        this.name = name;
//        this.idc = idc;
//        this.min_zu = min_zu;
//        this.jiao_yu = jiao_yu;
//        this.sex = sex;
//        this.hu_bie = hu_bie;
//        this.lei_xing = lei_xing;
//        this.mian_ji = mian_ji;
//        this.shu_mu = shu_mu;
//        this.id = id;
//    }

    public Person(int id, String hu_bie, String idc, String name, String jiao_yu, String lei_xing, String mian_ji, String min_zu, String shu_mu, String sex) {
        this.id = id;
        this.hu_bie = hu_bie;
        this.idc = idc;
        this.name = name;
        this.jiao_yu = jiao_yu;
        this.lei_xing = lei_xing;
        this.mian_ji = mian_ji;
        this.min_zu = min_zu;
        this.shu_mu = shu_mu;
        this.sex = sex;
    }

    public Person( String hu_bie, String idc, String name, String jiao_yu, String lei_xing, String mian_ji, String min_zu, String shu_mu, String sex) {
        this.hu_bie = hu_bie;
        this.idc = idc;
        this.name = name;
        this.jiao_yu = jiao_yu;
        this.lei_xing = lei_xing;
        this.mian_ji = mian_ji;
        this.min_zu = min_zu;
        this.shu_mu = shu_mu;
        this.sex = sex;
    }
    public Person() {

    }
}

三、Util,链接数据库

import java.sql.*;

public class jdbcUtil {
    public static Connection getConnection() throws Exception, SQLException {
        Connection connection = null;
        PreparedStatement pstmt = null;
        ResultSet re = null;

        Class.forName("com.mysql.cj.jdbc.Driver");
        connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/person ?useUnicode=true&characterEncoding=utf8", "root", "123456");

        return connection;
    }
    public static void close(Connection connection)
    {

        if(connection != null)
        {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    public static void close(PreparedStatement preparedStatement)  {
        if(preparedStatement != null)
        {
            try {
                preparedStatement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    public static void close(ResultSet resultSet)  {
        if(resultSet != null)
        {
            try {
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

四、Servlet

import com.pojo.Person;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;

@WebServlet("/Servlet")
public class Servlet extends HttpServlet {
    Service service = new Service();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");
        String method = request.getParameter("method");

        if ("add".equals(method)) {
            try {
                add(request, response);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if ("del".equals(method)) {
            try {
                del(request, response);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if ("update".equals(method)) {
            try {
                update(request, response);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if ("selete".equals(method)) {
            try {
                sel(request, response);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        else if ("r_updata".equals(method))
        {
            try {
                r_updata(request, response);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
else if("getbyname".equals(method))
{
try{
getbyname(request , response);
}catch(Exception e)
{
e.printStackTrace();
}
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
private void update(HttpServletRequest request, HttpServletResponse response) throws Exception {
request.setCharacterEncoding("utf-8");
//获取数据
int id = Integer.parseInt(request.getParameter("id"));
String hu_bie = request.getParameter("hu_bie");
String idc = request.getParameter("idc");
String name = request.getParameter("name");
String jiao_yu = request.getParameter("jiao_yu");
String lei_xing = request.getParameter("lei_xing");
String mian_ji = request.getParameter("mian_ji");
String min_zu = request.getParameter("min_zu");
String shu_mu = request.getParameter("shu_mu");
String sex = request.getParameter("sex");
Person person = new Person(id,hu_bie,idc,name,jiao_yu,lei_xing,mian_ji,min_zu,shu_mu,sex);

//添加后消息显示
if(service.updata(person)) {
request.setAttribute("message", "修改成功");
} else {
request.setAttribute("message", "修改失败");
}
request.getRequestDispatcher("Servlet?method=selete").forward(request,response);
}

private void sel(HttpServletRequest request, HttpServletResponse response) throws Exception {
request.setCharacterEncoding("utf-8");

List<Person> list = service.list();
request.setAttribute("list" , list);
request.getRequestDispatcher("sel.jsp").forward(request,response);
}
private void getbyname(HttpServletRequest request, HttpServletResponse response) throws Exception{
request.setCharacterEncoding("utf-8");
String name = request.getParameter("name");

List<Person> list = service.getbyname(name);
int count = service.getbyname_if(name);
if( count != 0) {
request.setAttribute("message", "查询成功");
request.setAttribute("list" , list);
request.getRequestDispatcher("sel.jsp").forward(request , response);
} else {
request.setAttribute("message", "查询失败");
request.getRequestDispatcher("getbyname.jsp").forward(request , response);
}
}

private void del(HttpServletRequest request, HttpServletResponse response) throws Exception {
request.setCharacterEncoding("utf-8");
//获取数据
int id = Integer.parseInt(request.getParameter("id"));
Person person = new Person();
person.setId(id);
//添加后消息显示
if(service.del(person)) {
request.setAttribute("message", "删除成功");
} else {
request.setAttribute("message", "删除");
}
request.getRequestDispatcher("Servlet?method=selete").forward(request,response);
}
private void r_updata(HttpServletRequest request, HttpServletResponse response) throws Exception {
request.setCharacterEncoding("utf-8");

int id = Integer.parseInt(request.getParameter("id"));
Person person = service.r_list(id);

request.setAttribute("person", person);
request.getRequestDispatcher("updata.jsp").forward(request, response);

}
private void add(HttpServletRequest request, HttpServletResponse response) throws Exception {
request.setCharacterEncoding("utf-8");
//获取数据
String hu_bie = request.getParameter("hu_bie");
String idc = request.getParameter("idc");
String name = request.getParameter("name");
String jiao_yu = request.getParameter("jiao_yu");
String lei_xing = request.getParameter("lei_xing");
String mian_ji = request.getParameter("mian_ji");
String min_zu = request.getParameter("min_zu");
String shu_mu = request.getParameter("shu_mu");
String sex = request.getParameter("sex");

Person person = new Person(hu_bie,idc,name,jiao_yu,lei_xing,mian_ji,min_zu,shu_mu,sex);

//添加后消息显示
if(service.add(person)) {
request.setAttribute("message", "添加成功");
} else {
request.setAttribute("message", "添加失败,请重新录入");
}
request.getRequestDispatcher("add.jsp").forward(request,response);
}


}

五、service

import com.dao.AddDao;
import com.dao.DeleteDao;
import com.dao.SeleteDao;
import com.dao.UpdataDao;
import com.pojo.Person;

import java.util.ArrayList;
import java.util.List;

public class Service {
    public boolean add(Person person) throws Exception {
        AddDao addDao = new AddDao();
        boolean f = false;
        if(true) //!person.name(person.getName())
                {
                    addDao.add(person);
                    f=true;
                 }
                return f;
            }

    public List<Person> list() throws Exception {
        SeleteDao seleteDao = new SeleteDao();
        List<Person>list = new ArrayList<>();
        list = seleteDao.selectall();
        return list;
    }
    public boolean updata(Person person) throws Exception {
        UpdataDao updataDao = new UpdataDao();
            int count = updataDao.updata(person);
            if(count != 0)
                return true;
            return false;
    }
    public boolean del(Person person) throws Exception {
        DeleteDao deleteDao = new DeleteDao();
        boolean f = false;
        if(true) //!person.name(person.getName())
        {
            deleteDao.delete(person);
            f=true;
        }
        return f;
    }
    public Person r_list(int id) throws Exception {
        SeleteDao seleteDao = new SeleteDao();
        Person person =  seleteDao.select_one(id);
        return person;
    }
public List<Person> getbyname(String name) throws Exception {
SeleteDao seleteDao = new SeleteDao();
List<Person>list = new ArrayList<>();
list = seleteDao.getbyname(name);
return list;
}

public int getbyname_if(String name) throws Exception {
SeleteDao seleteDao = new SeleteDao();
int count = seleteDao.getbyname_if(name);
return count;
}
}

六、JSP

1.菜单

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>第七次全国人口普查登记</title>
  </head>
  <body>
  <div align="center">

    <div class="a">
      <a href="add.jsp">信息登记</a>
    </div>
<div class="a">
<a href="getbyname.jsp">信息修改</a>
</div>
<div class="a">
<a href="getbyname.jsp">信息删除</a>
</div>
<div class="a">
<a href="Servlet?method=selete">信息浏览</a>
</div>

</div>
</body>
</html>

2.添加

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8" >
    <title>添加信息</title>
</head>

<body>
<%
    Object message = request.getAttribute("message");
    if(message!=null && !"".equals(message)){

%>
<script type="text/javascript">
    alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<div align="center">
<h1 style="color: black;">信息添加</h1>

<form action="Servlet?method=add" method="post">
     <table align="center" border="1" width="500">
         <tr>
               <td>户别: </td>
               <td>
                   <label>
                       <input type="radio" name="hu_bie" value="家庭户"checked>家庭户
                       <input type="radio" name="hu_bie" value="集体户">集体户
                   </label>
               </td>
         </tr>
         <tr>
             <td>住房类型: </td>
             <td>
                  <label>
                      <input type="radio" name="lei_xing" value="家庭住宅" checked>家庭住宅
                      <input type="radio" name="lei_xing" value="集体住所" >集体住所
                      <input type="radio" name="lei_xing" value="工作地住所" >工作地住所
                      <input type="radio" name="lei_xing" value="其他住宅" >其他住宅
                      <input type="radio" name="lei_xing" value="无住宅" >无住宅
                  </label>
             </td>
         </tr>
         <tr>
             <td>本户现住房面积: </td>
             <td>
                 <label>
                     <input type="text" name="mian_ji"/>平方米
                 </label>
             </td>
         </tr>
         <tr>
             <td>本户现住房间数: </td>
             <td>
                 <label>
                     <input type="text" name="shu_mu" /></label>
             </td>
         </tr>
         <tr>
             <td>户主姓名: </td>
             <td>
                 <label>
                     <input type="text" name="name" />
                 </label>
             </td>
         </tr>

         <tr>
             <td>身份证号码: </td>
             <td>
                 <label>
                     <input type="text" name="idc" maxlength="13" />
                 </label>
             </td>
         </tr>
         <tr>
             <td>性别: </td>
             <td>
                 <label>
                     <input type="radio" name="sex" value="男" checked><input type="radio" name="sex" value="女"></label>
             </td>
         </tr>
         <tr>
             <td>民族: </td>
             <td>
                 <label>
                     <input type="text" name="min_zu"/>
                 </label>
             </td>
         </tr>
         <tr>
             <td>受教育程度: </td>
             <td>
                 <label>
                     <select name="jiao_yu">
                         <option value="研究生">研究生</option>
                         <option value="大学本科">大学本科</option>
                         <option value="大学专科">大学专科</option>
                         <option value="高中" selected>高中</option>
                         <option value="初中">初中</option>
                         <option value="小学">小学</option>
                         <option value="未上过学">未上过学</option>
                     </select>
                 </label>
             </td>
         </tr>
         <tr align="center">
             <td colspan="2">
                 <input type="submit" value="提交" />
                 <input type="reset" value="重置" />
             </td>
         </tr>
      </table>
      <a href="index.jsp">返回主页</a>
</form>
</div>
</body>
</html>

3.查询

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.List" %>
<%@ page import="com.pojo.Person" %>
<%-- Created by IntelliJ IDEA. User: wanghongbing Date: 2022/10/16 Time: 16:18 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%} %> <div align="center"> <h1 style="color: black;">信息列表</h1> <form action="Servlet?method=selete" method="post"> <table border="1px"> <tr> <td>id</td> <td>户 别</td> <td>住房类型</td> <td>本户现住房面积</td>0 <td>本户现住房间数</td> <td>户主姓名</td> <td>身份证号码</td> <td>性别</td> <td>民族</td> <td>受教育程度</td> </tr> <!-- forEach遍历出adminBeans --> <c:forEach items="${list}" var="item"> <tr> <td>${item.id}</td> <td>${item.hu_bie}</td> <td>${item.lei_xing}</td> <td>${item.mian_ji}</td> <td>${item.shu_mu}</td> <td>${item.name}</td> <td>${item.idc}</td> <td>${item.sex}</td> <td>${item.min_zu}</td> <td>${item.jiao_yu}</td> <td><a href="Servlet?method=del&&id=${item.id}">删除</a></td> <td><a href="Servlet?method=r_updata&&id=${item.id}">修改</a></td> </tr> </c:forEach> </table> </form> </div> </body> </html>

4.修改

<%@ page import="com.pojo.Person" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: wanghongbing
Date: 2022/10/16
Time: 16:18
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>修改信息</title>
</head>
<body>
<%
Person persons = (Person) request.getAttribute("person");
%>
<div align="center">
<h1 style="color: black;">信息修改</h1>
<form action="Servlet?method=update&&id=<%=persons.getId()%>" method="post">
<table border="1px">

<tr>
<td>id<input type="text" name="id" value="<%=persons.getId()%>" readonly="readonly"/></td>
</tr>

<tr>
<td>身份证号<input type="text" name="idc" value="<%=persons.getIdc()%>"/></td>
</tr>

<tr>
<td>户主名<input type="text" name="name" value="<%=persons.getName()%>"/></td>
</tr>

<tr>
<td>本户现住房面积<input type="text" name="mian_ji" value="<%=persons.getMian_ji()%>"/></td>
</tr>
<tr>
<td>民族<input type="text" name="min_zu" value="<%=persons.getMin_zu()%>"/></td>
</tr>
<tr>
<td>本户现住房间数<input type="text" name="shu_mu" value="<%=persons.getShu_mu()%>"/></td>
</tr>
<tr>
<td>户别<input value="<%=persons.getHu_bie()%>"/></td>
<td>
<label>
<input type="radio" name="hu_bie" value="家庭户">家庭户
<input type="radio" name="hu_bie" value="集体户">集体户
</label>
</td>
</tr>
<tr>
<td>性别<input value="<%=persons.getSex()%>"/></td>
<td>
<label>
<input type="radio" name="sex" value="男">男
<input type="radio" name="sex" value="女">女
</label>
</td>
</tr>
<tr>
<td>受教育程度<input value="<%=persons.getJiao_yu()%>"/></td>
<td>
<label>
<select name="jiao_yu">
<option value="研究生">研究生</option>
<option value="大学本科">大学本科</option>
<option value="大学专科">大学专科</option>
<option value="高中" >高中</option>
<option value="初中">初中</option>
<option value="小学">小学</option>
<option value="未上过学">未上过学</option>
</select>
</label>
</td>
</tr>
<tr>
<td>住房类型<input value="<%=persons.getLei_xing()%>"/></td>
<td>
<label>
<input type="radio" name="lei_xing" value="家庭住宅" >家庭住宅
<input type="radio" name="lei_xing" value="集体住所" >集体住所
<input type="radio" name="lei_xing" value="工作地住所" >工作地住所
<input type="radio" name="lei_xing" value="其他住宅" >其他住宅
<input type="radio" name="lei_xing" value="无住宅" >无住宅
</label>
</td>
</tr>
<tr align="center">
<td colspan="2">
<input type="submit" value="提交" />
<input type="reset" value="重置" />
</td>
</tr>
</table>
<a href="index.jsp">返回主页</a>

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

5、按姓名模糊查询

<%--
  Created by IntelliJ IDEA.
  User: wanghongbing
  Date: 2022/10/19
  Time: 20:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>信息查询</title>
</head>
<body>
    <%
    Object message = request.getAttribute("message");
     if(message!=null && !"".equals(message)){

    %>
    <script type="text/javascript">
        alert("<%=request.getAttribute("message")%>")
    </script>
    <%
        }
    %>
<div align="center">
    <h1 style="color: black;">信息查询</h1>
<form action="Servlet?method=getbyname" method="post">
    请输入户主姓名:<input type="text" name="name" /><br>
    <input type="submit" value="查询" />
</form>
</div>
</body>
</html>

 

PS:删除, 修改,进行了升级。

posted @ 2022-10-18 20:12  旺旺大菠萝  阅读(411)  评论(0编辑  收藏  举报