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


     

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

     \

    DAO部分

    package Dao;

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

    import people.people;
    import util.DBUtil;

    /**
    * 课程Dao
    * Dao层操作数据
    * @author Hu
    *
    */
    public class Dao {

    /**
    * 添加
    * @param course
    * @return
    */
    public boolean add(people people) {
    String sql = "insert into zhufang(name,idc,sex,min_zu,jiao_yu,hu_bie,zhu_fang_lei_bie,S,N) values('" + people.getName() + "','" + people.getIdc() + "','" + people.getSex() + "','" + people.getMin_zu() + "','" + people.getJiao_yu() + "','" + people.getHu_bie() + "','" + people.getZhu_fang_lei_bie() + "','" + people.getS() + "','" + people.getN() + "')";
    //创建数据库链接
    Connection conn = DBUtil.getConn();
    Statement state = null;
    boolean f = false;
    int a = 0;

    try {
    state = conn.createStatement();
    a = state.executeUpdate(sql);
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    //关闭连接
    DBUtil.close(state, conn);
    }

    if (a > 0) {
    f = true;
    }
    return f;
    }

    /**
    * 删除
    *
    * @param id
    * @return
    */
    public boolean delete (int id) {
    boolean f = false;
    String sql = "delete from zhufang where id='" + id + "'";

    Connection conn = DBUtil.getConn();
    Statement state = null;
    int a = 0;

    try {
    state = conn.createStatement();
    a = state.executeUpdate(sql);
    } catch (SQLException e) {
    e.printStackTrace();
    } finally {
    DBUtil.close(state, conn);
    }

    if (a > 0) {
    f = true;
    }
    return f;
    }

    /**
    * 修改
    * @param name
    * @param pass
    */
    /**
    * @param people
    * @return
    */
    public boolean update(people people) {
    String sql = "update zhufang set name='" + people.getName() + "', idc='" + people.getIdc() + "', sex='" + people.getSex() + "', min_zu='" + people.getMin_zu() + "', jiao_yu='" + people.getJiao_yu()
    + "' where id='" + people.getId() + "'";
    Connection conn = DBUtil.getConn();
    Statement state = null;
    boolean f = false;
    int a = 0;

    try {
    state = conn.createStatement();
    a = state.executeUpdate(sql);
    } catch (SQLException e) {
    e.printStackTrace();
    } finally {
    DBUtil.close(state, conn);
    }

    if (a > 0) {
    f = true;
    }
    return f;
    }

    /**
    * 验证课程名称是否唯一
    * true --- 不唯一
    * @param name
    * @return
    */
    public boolean leibie(String name) {
    boolean flag = false;
    String sql = "select name from zhufang where name = '" + name + "'";
    Connection conn = DBUtil.getConn();
    Statement state = null;
    ResultSet rs = null;

    try {
    state = conn.createStatement();
    rs = state.executeQuery(sql);
    while (rs.next()) {
    flag = true;
    }
    } catch (SQLException e) {
    e.printStackTrace();
    } finally {
    DBUtil.close(rs, state, conn);
    }
    return flag;
    }

    /**
    * 通过ID得到课程信息
    * @param id
    * @return
    */
    public people getById(int id) {
    String sql = "select * from zhufang where id ='" + id + "'";
    Connection conn = DBUtil.getConn();
    Statement state = null;
    ResultSet rs = null;
    people people = null;

    try {
    state = conn.createStatement();
    rs = state.executeQuery(sql);
    while (rs.next()) {
    String name = rs.getString("name");
    String min_zu = rs.getString("min_zu");
    String jiao_yu = rs.getString("jiao_yu");
    String idc = rs.getString("idc");
    String sex = rs.getString("sex");
    int ida = rs.getInt("id");
    people = new people(ida,name,idc,min_zu,jiao_yu,sex);
    }
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    DBUtil.close(rs, state, conn);
    }

    return people;
    }

    /**
    * 通过name得到Course
    * @param name
    * @return
    */
    public people getByName(String name) {
    String sql = "select * from zhufang where name ='" + name + "'";
    Connection conn = DBUtil.getConn();
    Statement state = null;
    ResultSet rs = null;
    people people = null;

    try {
    state = conn.createStatement();
    rs = state.executeQuery(sql);
    while (rs.next()) {
    int id = rs.getInt("id");
    String name1 = rs.getString("name");
    String zhu_fang_lei_bie = rs.getString("zhu_fang_lei_bie");
    String hu_bie = rs.getString("hu_bie");
    String idc = rs.getString("idc");
    String jiao_yu = rs.getString("jiao_yu");
    String min_zu = rs.getString("min_zu");
    int S = rs.getInt("S");
    int N = rs.getInt("N");
    String sex = rs.getString("sex");
    people = new people(id,hu_bie,zhu_fang_lei_bie,name1,idc,min_zu,jiao_yu,sex,S,N);
    }
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    DBUtil.close(rs, state, conn);
    }

    return people;
    }

    /**
    * 查找
    * @param name
    * @param teacher
    * @param classroom
    * @return
    */
    public List<people> search(String name,String sex, String min_zu, String jiao_yu) {
    String sql = "select * from zhufang where ";

    if (name != "") {
    sql += "name like '%" + name + "%'";
    }
    else if (min_zu != "") {
    sql += "min_zu like '%" + min_zu + "%'";
    }
    else if (jiao_yu != "") {
    sql += "jiao_yu like '%" + jiao_yu + "%'";
    }
    else if (sex != "") {
    sql += "sex like '%" + sex + "%'";
    }
    else
    {
    }

    List<people> list = new ArrayList<>();
    Connection conn = DBUtil.getConn();
    Statement state = null;
    ResultSet rs = null;

    try {
    state = conn.createStatement();
    rs = state.executeQuery(sql);
    people bean = null;
    while (rs.next()) {
    int id = rs.getInt("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");
    bean = new people(id,name2,idc2,min_zu2,jiao_yu2,sex2);
    list.add(bean);
    }
    } catch (SQLException e) {
    e.printStackTrace();
    } finally {
    DBUtil.close(rs, state, conn);
    }

    return list;
    }

    /**
    * 全部数据
    * @param name
    * @param teacher
    * @param classroom
    * @return
    */
    public List<people> list() {
    String sql = "select * from zhufang";
    List<people> list = new ArrayList<>();
    Connection conn = DBUtil.getConn();
    Statement state = null;
    ResultSet rs = null;

    try {
    state = conn.createStatement();
    rs = state.executeQuery(sql);
    people bean = null;
    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("zhu_fang_lei_bie");
    int S2 = Integer.parseInt(rs.getString("S"));
    int N2 = Integer.parseInt(rs.getString("N"));
    bean = new people(id,hu_bie2,zhu_fang_lei_bie2,name2,idc2,min_zu2,jiao_yu2,sex2,S2,N2);
    list.add(bean);
    }
    } catch (SQLException e) {
    e.printStackTrace();
    } finally {
    DBUtil.close(rs, state, conn);
    }

    return list;
    }

    }

    Servlet部分

    package Servlet;

    import java.io.IOException;
    import java.util.List;

    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import people.people;
    import Service.Service;

    @WebServlet("/Servlet")
    public class Servlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    Service service = new Service();

    /**
    * 方法选择
    */
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    req.setCharacterEncoding("utf-8");
    String method = req.getParameter("method");

    if ("add".equals(method)) {
    add(req, resp);
    } else if ("del".equals(method)) {
    del(req, resp);
    } else if ("update".equals(method)) {
    update(req, resp);
    } else if ("search".equals(method)) {
    search(req, resp);
    } else if ("getbyid".equals(method)) {
    getById(req, resp);
    } else if ("getbyname".equals(method)) {
    getByName(req, resp);
    } else if ("list".equals(method)) {
    list(req, resp);
    }
    }

    /**
    * 添加
    * @param req
    * @param resp
    * @throws IOException
    * @throws ServletException
    */
    private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
    req.setCharacterEncoding("utf-8");
    //获取数据
    String hu_bie = req.getParameter("hu_bie");
    String zhu_fang_lei_bie = req.getParameter("zhu_fang_lei_bie");
    String name = req.getParameter("name");
    String idc = req.getParameter("idc");
    String min_zu = req.getParameter("min_zu");
    String jiao_yu = req.getParameter("jiao_yu");
    String sex = req.getParameter("sex");
    int S = Integer.parseInt(req.getParameter("S"));
    int N = Integer.parseInt(req.getParameter("N"));

    people people = new people(hu_bie,zhu_fang_lei_bie,name,idc,min_zu,jiao_yu,sex,S,N);

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

    /**
    * 全部
    * @param req
    * @param resp
    * @throws ServletException
    */
    private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
    req.setCharacterEncoding("utf-8");
    List<people> peoples = service.list();
    req.setAttribute("peoples", peoples);
    req.getRequestDispatcher("detail2.jsp").forward(req,resp);
    }

    /**
    * 通过ID得到Course
    * @param req
    * @param resp
    * @throws ServletException
    */
    private void getById(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
    req.setCharacterEncoding("utf-8");
    int id = Integer.parseInt(req.getParameter("id"));
    people people = service.getById(id);
    req.setAttribute("people", people);
    req.getRequestDispatcher("detail2.jsp").forward(req,resp);
    }

    /**
    * 通过名字查找
    * 跳转至删除
    * @param req
    * @param resp
    * @throws IOException
    * @throws ServletException
    */
    private void getByName(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
    req.setCharacterEncoding("utf-8");
    String name = req.getParameter("name");
    people people =service.getByName(name);
    if(people == null) {
    req.setAttribute("message", "查无此人!");
    req.getRequestDispatcher("del.jsp").forward(req,resp);
    } else {
    req.setAttribute("people", people);
    req.getRequestDispatcher("detail.jsp").forward(req,resp);
    }
    }

    /**
    * 删除
    * @param req
    * @param resp
    * @throws IOException
    * @throws ServletException
    */
    private void del(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
    req.setCharacterEncoding("utf-8");
    int id = Integer.parseInt(req.getParameter("id"));
    service.del(id);
    req.setAttribute("message", "删除成功!");
    req.getRequestDispatcher("del.jsp").forward(req,resp);
    }

    /**
    * 修改
    * @param req
    * @param resp
    * @throws IOException
    * @throws ServletException
    */
    private void update(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
    req.setCharacterEncoding("utf-8");
    int id = Integer.parseInt(req.getParameter("id"));
    String name = req.getParameter("name");
    String idc = req.getParameter("idc");
    String min_zu = req.getParameter("min_zu");
    String jiao_yu = req.getParameter("jiao_yu");
    String sex1 = req.getParameter("sex");
    people people = new people(id,name,idc,min_zu,jiao_yu,sex1);


    service.update(people);
    req.setAttribute("message", "修改成功");
    req.getRequestDispatcher("Servlet?method=list").forward(req,resp);
    }

    /**
    * 查找
    * @param req
    * @param resp
    * @throws ServletException
    */
    private void search(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
    req.setCharacterEncoding("utf-8");
    String name = req.getParameter("name");
    String min_zu = req.getParameter("min_zu");
    String jiao_yu = req.getParameter("jiao_yu");
    String sex = req.getParameter("sex");

    List<people> peoples = service.search(name,sex,min_zu,jiao_yu);
    req.setAttribute("peoples", peoples);
    req.getRequestDispatcher("list.jsp").forward(req,resp);
    }
    }

    服务层部分 

    package Service;

    import java.util.List;

    import Dao.Dao;
    import people.people;

    /**
    * Service
    * 服务层
    * @author Hu
    *
    */
    public class Service {

    Dao cDao = new Dao();

    /**
    * 添加
    * @param course
    * @return
    */
    public boolean add(people people) {
    boolean f = false;
    if(!cDao.leibie(people.getName())) {
    cDao.add(people);
    f = true;
    }
    return f;
    }

    /**
    * 删除
    */
    public void del(int id) {
    cDao.delete(id);
    }

    /**
    * 修改
    * @return
    */
    public void update(people people) {
    cDao.update(people);
    }

    /**
    * 通过ID得到一个Course
    * @return
    */
    public people getById(int id) {
    return cDao.getById(id);
    }

    /**
    * 通过Name得到一个Course
    * @return
    */
    public people getByName(String name) {
    return cDao.getByName(name);
    }

    /**
    * 查找
    * @return
    */
    public List<people> search(String name, String sex, String min_zu,String jiao_yu) {
    return cDao.search(name,sex,min_zu,jiao_yu);
    }

    /**
    * 全部数据
    * @return
    */
    public List<people> list() {
    return cDao.list();
    }
    }

    类的封装部分

    package people;

    public class people {
    String hu_bie;
    String zhu_fang_lei_bie;
    int S;
    int N;
    String name;
    String idc;
    String sex;
    String min_zu;
    String jiao_yu;
    int id;
    public people(int id,String name, String idc, String min_zu, String jiao_yu)
    {
    this.id = id;
    this.min_zu = min_zu;
    this.jiao_yu = jiao_yu;
    this.name = name;
    this.idc = idc;

    }
    public people(int id,String name, String idc, String min_zu, String jiao_yu,String sex) {
    this.id = id;
    this.sex = sex;
    this.min_zu = min_zu;
    this.jiao_yu = jiao_yu;
    this.name = name;
    this.idc = idc;

    }
    public people(String hu_bie, String zhu_fang_lei_bie, String name, String idc, String min_zu, String jiao_yu,String sex,int S,int N) {

    this.hu_bie = hu_bie;
    this.zhu_fang_lei_bie = zhu_fang_lei_bie;
    this.S = S;
    this.N = N;
    this.sex = sex;
    this.min_zu = min_zu;
    this.jiao_yu = jiao_yu;
    this.name = name;
    this.idc = idc;

    }
    public people(int id,String hu_bie, String zhu_fang_lei_bie, String name, String idc, String min_zu, String jiao_yu,String sex,int S,int N) {
    this.id = id;
    this.hu_bie = hu_bie;
    this.zhu_fang_lei_bie = zhu_fang_lei_bie;
    this.S = S;
    this.N = N;
    this.sex = sex;
    this.min_zu = min_zu;
    this.jiao_yu = jiao_yu;
    this.name = name;
    this.idc = idc;

    }
    public String getHu_bie() {
    return hu_bie;
    }
    public void setHu_bie(String hu_bie) {
    this.hu_bie = hu_bie;
    }
    public String getZhu_fang_lei_bie() {
    return zhu_fang_lei_bie;
    }
    public void setZhu_fang_lei_bie(String zhu_fang_lei_bie) {
    this.zhu_fang_lei_bie = zhu_fang_lei_bie;
    }
    public int getS() {
    return S;
    }
    public void setS(int s) {
    S = s;
    }
    public int getN() {
    return N;
    }
    public void setN(int n) {
    N = n;
    }
    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 getSex() {
    return sex;
    }
    public void setSex(String sex) {
    this.sex = sex;
    }
    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 int getId() {
    return id;
    }
    public void setId(int id) {
    this.id = id;
    }


    }

    数据库连接

    package util;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;


    public class DBUtil {

    public static String db_url = "jdbc:mysql://localhost:3306/pu_cha?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone = GMT&allowPublicKeyRetrieval=true";
    public static String db_user = "root";
    public static String db_pass = "root";

    public static Connection getConn () {
    Connection conn = null;

    try {
    Class.forName("com.mysql.cj.jdbc.Driver");//加载驱动
    conn = DriverManager.getConnection(db_url, db_user, db_pass);
    } catch (Exception e) {
    e.printStackTrace();
    }

    return conn;
    }

    /*10鍏抽棴杩炴帴*/
    public static void close (Statement state, Connection conn) {
    if (state != null) {
    try {
    state.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }

    if (conn != null) {
    try {
    conn.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    }

    public static void close (ResultSet rs, Statement state, Connection conn) {
    if (rs != null) {
    try {
    rs.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }

    if (state != null) {
    try {
    state.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }

    if (conn != null) {
    try {
    conn.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    }

    public static void main(String[] args) throws SQLException {
    }
    }

    主菜单

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>人口普查系统</title>

    </head>
    <body>
    <div align="center">

    <div class="a">
    <a href="add.jsp">信息登记</a>
    </div>
    <div class="a">
    <a href="Servlet?method=list">信息修改</a>
    </div>
    <div class="a">
    <a href="del.jsp">信息删除</a>
    </div>
    <div class="a">
    <a href="searchlist.jsp">信息查询</a>
    </div>
    </div>
    </body>
    </html>

    添加信息 

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <!DOCTYPE html>
    <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>
    <a href="menu.jsp">返回主页</a>
    <form name="form1" action="Servlet?method=add" method="post" onsubmit="return check()">
    <div class="a">
    户 别
    集体户<input type="radio" id="hu_bie" name="hu_bie" value="collectivehousehold" >
    家庭户<input type="radio" id="hu_bie" name="hu_bie" value="households" >
    </div>
    <div class="a">
    住房类型
    家庭住宅<input type="radio" id="zhu_fang_lei_bie" name="zhu_fang_lei_bie" value="familyhome" >
    集体住所<input type="radio" id="zhu_fang_lei_bie" name="zhu_fang_lei_bie" value="collectivehouseing" >
    工作地住所<input type="radio" id="zhu_fang_lei_bie" name="zhu_fang_lei_bie" value="workplacehousing" >
    其他住宅<input type="radio" id="zhu_fang_lei_bie" name="zhu_fang_lei_bie" value="otherresidential" >
    无住宅<input type="radio" id="zhu_fang_lei_bie" name="zhu_fang_lei_bie" value="noresidence" >
    </div>
    <div class="a">
    现住房面积<input type="text" id="S" name="S" />
    </div>
    <div class="a">
    现住房房间数<input type="text" id="N" name="N" />
    </div>
    <div class="a">
    户主姓名<input type="text" id="name" name="name" />
    </div>
    <div class="a">
    身份证号码<input type="text" id="idc" name="idc" />
    </div>
    <div class="a">
    性别
    男<input type="radio" name="sex" value="nan" >
    女<input type="radio" name="sex" value="nv" >
    </div>
    <div class="a">
    民族<input type="text" id="min_zu" name="min_zu" />
    </div>
    <div class="a">
    受教育程度
    研究生<input type="radio" id="jiao_yu" name="jiao_yu" value="postgraduate" >
    大学本科<input type="radio" id="jiao_yu" name="jiao_yu" value="undergraduate" >
    大学专科<input type="radio" id="jiao_yu" name="jiao_yu" value="college" >
    高中<input type="radio" id="jiao_yu" name="jiao_yu" value="highschool" >
    初中<input type="radio" id="jiao_yu" name="jiao_yu" value="juniorhighschool" >
    小学<input type="radio" id="jiao_yu" name="jiao_yu" value="primaryschool" >
    未上过学<input type="radio" id="jiao_yu" name="jiao_yu" value="uneducated" >
    </div>
    <div class="a">
    <button type="submit" class="b">保   存</button>
    </div>
    </form>
    </div>
    <script type="text/javascript">
    function check() {
    var S = document.form1.S.value;
    var N = document.form1.N.value;
    var idc = document.form1.idc.value;
    var name = document.form1.name.value;
    var jiao_yu = document.form1.jiao_yu.value;
    var min_zu = document.form1.min_zu.value;;
    var idc = document.form1.idc.value;
    //非空
    if(jiao_yu == '') {
    alert('受教育程度为空');
    jiao_yu.focus();
    return false;
    }
    if(min_zu == '') {
    alert('民族为空');
    min_zu.focus();
    return false;
    }
    if(S == '') {
    alert('住房面积为空');
    S.focus();
    return false;
    }
    if(N == '') {
    alert('房间数为空');
    N.focus();
    return false;
    }if(idc == '') {
    alert('身份证号码为空');
    idc.focus();
    return false;
    }if(name == '') {
    alert('户主名为空');
    name.focus();
    return false;
    }if(idc.length!=18)
    {
    alert('身份证号码位数错误');
    idc.focus();
    return false;
    }if(check_word(idc))
    {
    alert('身份证号码包含字母');
    idc.focus();
    return false;
    }
    if ((document.theForm.S.value.indexOf("-") == 0)||!(document.theForm.S.value.indexOf(".") == -1)){
    alert("住房面积不能为小数或负数");
    document.theForm.S.focus();
    return false;
    }
    if ((document.theForm.N.value.indexOf("-") == 0)||!(document.theForm.N.value.indexOf(".") == -1)){
    alert("房间数不能为小数或负数");
    document.theForm.N.focus();
    return false;
    }
    }
    function check_word(str)
    { var arr = ["a", "b", "c", "d", "e", "f", "g", "h","i","j", "k", "l", "m", "n", "o", "p", "q","r", "s", "t", "u", "v", "w", "x", "y","z","A", "B", "C", "D", "E", "F", "G", "H","I","J", "K", "L", "M", "N", "O", "P", "Q","R","S", "T", "U", "V", "W", "X", "Y", "Z"];
    for (var i = 0; i < arr.length; i++)
    {
    for (var j = 0; j < str.length; j++)
    {
    if (arr[i] == str.charAt(j))
    {
    if(arr[i]=="X"&&j==18)
    {
    return false;
    }
    return true;
    }
    }
    }
    return false;
    }
    </script>
    </body>
    </html>

    删除信息

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <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>
    <a href="menu.jsp">返回主页</a>
    <form action="Servlet?method=getbyname" method="post" onsubmit="return check()">
    <div class="a">
    户主性名<input type="text" id="name" name="name"/>
    </div>
    <div class="a">
    <button type="submit" class="b">查   找</button>
    </div>
    </form>
    </div>
    <script type="text/javascript">
    function check() {
    var name = document.getElementById("name");;

    //非空
    if(name.value == '') {
    alert('户主名为空');
    name.focus();
    return false;
    }
    }
    </script>
    </body>
    </html>

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>人口登记信息删除</title>
    <style>
    .a{
    margin-top: 20px;
    }
    .b{
    font-size: 20px;
    160px;
    color: white;
    background-color: greenyellow;
    }
    .tb, td {
    border: 1px solid black;
    font-size: 22px;
    }
    </style>
    </head>
    <body>
    <div align="center">
    <h1 style="color: black;">人口登记信息删除</h1>
    <a href="menu.jsp">返回主页</a>
    <table class="tb">
    <tr>
    <td>户主姓名</td>
    <td>${people.name}</td>
    </tr>
    <tr>
    <td>身份证号码</td>
    <td>${people.idc}</td>
    </tr>
    <tr>
    <td>性别</td>
    <td>${people.sex}</td>
    </tr>
    <tr>
    <td>民族</td>
    <td>${people.min_zu}</td>
    </tr>
    <tr>
    <td>受教育程度</td>
    <td>${people.jiao_yu}</td>
    </tr>
    </table>
    <div class="a">
    <a onclick="return check()" href="Servlet?method=del&id=${people.id}">删   除</a>
    </div>
    </div>
    <script type="text/javascript">
    function check() {
    if (confirm("真的要删除吗?")){
    return true;
    }else{
    return false;
    }
    }
    </script>
    </body>
    </html>

    遍历输出信息

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>信息列表</title>

    </head>
    <body>
    <div align="center">
    <h1 style="color: black;">信息列表</h1>
    <a href="menu.jsp">返回主页</a>
    <table class="tb">
    <tr>
    <td>id</td>
    <td>户主</td>
    <td>身份证号码</td>
    <td>性别</td>
    <td>民族</td>
    <td>受教育程度</td>
    </tr>
    <!-- forEach遍历出adminBeans -->
    <c:forEach items="${peoples}" var="item" varStatus="status">
    <tr>
    <td>${item.id}</td>
    <td>${item.name}</td>
    <td>${item.idc}</td>
    <td>${item.sex}</td>
    <td>${item.min_zu}</td>
    <td>${item.jiao_yu}</td>

    </tr>
    </c:forEach>
    </table>
    </div>
    </body>
    </html>

    查询信息

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>人口登记信息查询</title>

    </head>
    <body>
    <div align="center">
    <h1 style="color: black;">人口登记信息查询</h1>
    <a href="menu.jsp">返回主页</a>
    <form action="Servlet?method=search" method="post" onsubmit="return check()">
    <div class="a">
    户主<input type="text" id="name" name="name"/>
    </div>
    <div class="a">
    性别<input type="text" id="sex" name="sex" />
    </div>
    <div class="a">
    民族<input type="text" id="min_zu" name="min_zu" />
    </div>
    <div class="a">
    受教育程度<input type="text" id="jiao_yu" name="jiao_yu" />
    </div>

    <div class="a">
    <button type="submit" class="b">查&nbsp;&nbsp;&nbsp;询</button>
    </div>
    </form>
    </div>
    <script type="text/javascript">
    function check() {
    var name = document.getElementById("name");;
    var sex = document.getElementById("sex");
    var min_zu = document.getElementById("min_zu");
    var jiao_yu = document.getElementById("jiao_yu");

    if(jiao_yu.value == '') {
    alert('受教育程度为空');
    jiao_yu.focus();
    return false;
    }
    }if(name.value == '') {
    alert('户主名为空');
    name.focus();
    return false;
    }
    if(min_zu.value == '') {
    alert('民族为空');
    min_zu.focus();
    return false;
    }
    if(sex.value == '') {
    alert('民族为空');
    sex.focus();
    return false;
    }

    }
    </script>
    </body>
    </html>

    修改信息

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</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>
    <a href="menu.jsp">返回主页</a>
    <table class="tb">
    <tr>
    <td>id</td>
    <td>户主</td>
    <td>身份证号码</td>
    <td>性别</td>
    <td>民族</td>
    <td>受教育程度</td>
    <td>户别</td>
    <td>住房类型</td>
    </tr>
    <c:forEach items="${peoples}" var="item">
    <tr>
    <td>${item.id}</td>
    <td>${item.name}</td>
    <td>${item.idc}</td>
    <td>${item.sex}</td>
    <td>${item.min_zu}</td>
    <td>${item.jiao_yu}</td>
    <td>${item.hu_bie}</td>
    <td>${item.zhu_fang_lei_bie}</td>
    </tr>
    </c:forEach>
    <form action="Servlet?method=update" method="post" onsubmit="return check()">
    <tr>
    <td>id<input type="text" id="id" name="id"/></td>
    </tr>
    <tr>
    <td>户主名<input type="text" id="name" name="name"/></td>
    </tr>
    <tr>
    <td>身份证号<input type="text" id="idc" name="idc" /></td>
    </tr>
    <tr>
    <td>性别<input type="text" id="sex" name="sex" /></td>
    </tr>
    <tr>
    <td>民族<input type="text" id="min_zu" name="min_zu" /></td>
    </tr>
    <tr>
    <td>受教育程度<input type="text" id="jiao_yu" name="jiao_yu" /></td>
    </tr>
    <tr>
    <td><button type="submit" class="b">保存</button></td>
    </tr>
    </form>
    </table>
    </div>
    <script type="text/javascript">
    function check() {
    var id = document.getElementById("id");
    var idc = document.getElementById("idc");
    var name = document.getElementById("name");
    var jiao_yu = document.getElementById("jiao_yu");
    var min_zu = document.getElementById("min_zu");
    var sex = document.getElementById("sex");

    //非空
    if(id.value == '') {
    alert('id为空');
    id.focus();
    return false;
    }
    if(jiao_yu.value == '') {
    alert('受教育程度为空');
    jiao_yu.focus();
    return false;
    }
    if(min_zu.value == '') {
    alert('民族为空');
    min_zu.focus();
    return false;
    }
    if(idc.value == '') {
    alert('身份证号码为空');
    idc.focus();
    return false;
    }if(name.value == '') {
    alert('户主名为空');
    name.focus();
    return false;
    }
    if(sex.value == '') {
    alert('性别为空');
    sex.focus();
    return false;
    }


    }
    </script>
    </body>
    </html>

  • 相关阅读:
    团队十日冲刺1
    第八周学习进度
    人月神话阅读笔记02
    课堂练习-顶会热词统计
    第七周学习进度
    《vim — vimrc的设置》
    《开发板 — 调试串口》
    《网络编程 — 127.0.0.1的作用》
    《网络编程 — INADDR_ANY的含义》
    《开发板 — 上查看串口信息》
  • 原文地址:https://www.cnblogs.com/huangmouren233/p/13960877.html
Copyright © 2020-2023  润新知