人口普查系统完结(html+servlet)

人口普查系统的要求已经在前面的博客里面发了,这是我用html+servlet写的,下面是我的工程目录。

人口普查系统完结(html+servlet)

 

 

 这里面的login 和zhuce是没有的内容我还没添加进去不用管,bean层的password也没用。

com.Bean包

Information.java

package com.Bean;

public class Information {
private String hubie;
private String zhufangleixing;
private String zhufangmianji;
private String fangjianshu;
private String name;
private String id;
private String sex;
private String minzu;
private String jiaoyuchengdu;
public String getHubie() {
    return hubie;
}
public void setHubie(String hubie) {
    this.hubie = hubie;
}
public String getZhufangleixing() {
    return zhufangleixing;
}
public void setZhufangleixing(String zhufangleixing) {
    this.zhufangleixing = zhufangleixing;
}
public String getZhufangmianji() {
    return zhufangmianji;
}
public void setZhufangmianji(String zhufangmianji) {
    this.zhufangmianji = zhufangmianji;
}
public String getFangjianshu() {
    return fangjianshu;
}
public void setFangjianshu(String fangjianshu) {
    this.fangjianshu = fangjianshu;
}
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 getJiaoyuchengdu() {
    return jiaoyuchengdu;
}
public void setJiaoyuchengdu(String jiaoyuchengdu) {
    this.jiaoyuchengdu = jiaoyuchengdu;
}
}

com.Dao包

Mannger.java(这个里面是封装的各种方法,例如添加修改等等)

package com.Dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.Bean.Information;
import com.Util.utils;
public class Mannger {

    public void add(Information A) throws ClassNotFoundException, SQLException {  //添加信息
        Connection connection = utils.getConnection();
        String sql = "insert into renkou(hubie,zhufangleixing,zhufangmianji,fangjianshu,name,id,sex,minzu,jiaoyuchengdu) values(?,?,?,?,?,?,?,?,?)";
        PreparedStatement preparedStatement = null;
        try {
             //������䴫�����
             preparedStatement = connection.prepareStatement(sql);
           // preparedStatement = connection.prepareStatement(sql);
             preparedStatement.setString(1, A.getHubie());
             preparedStatement.setString(2, A.getZhufangleixing());
             preparedStatement.setString(3, A.getZhufangmianji());
             preparedStatement.setString(4, A.getFangjianshu());
             preparedStatement.setString(5, A.getName());
             preparedStatement.setString(6, A.getId());
             preparedStatement.setString(7, A.getSex());
             preparedStatement.setString(8, A.getMinzu());
             preparedStatement.setString(9, A.getJiaoyuchengdu());
             System.out.println(A.getHubie());
             preparedStatement.executeUpdate();
             } catch (SQLException e) {
                // TODO Auto-generated catch block
               e.printStackTrace();
            }finally {

            }
    }
    public void update(Information A,String name) throws ClassNotFoundException, SQLException {    //修改信息
        Connection connection = utils.getConnection();
        String sql = "update renkou set hubie = ?,zhufangleixing = ?,zhufangmianji = ?,fangjianshu = ?,name= ?,id =?  ,sex = ?,minzu=?,jiaoyuchengdu=? where name = ?";
        PreparedStatement preparedStatement = null;
        try {
             //������䴫�����
             preparedStatement = connection.prepareStatement(sql);
           // preparedStatement = connection.prepareStatement(sql);
             preparedStatement.setString(1, A.getHubie());
             preparedStatement.setString(2, A.getZhufangleixing());
             preparedStatement.setString(3, A.getZhufangmianji());
             preparedStatement.setString(4, A.getFangjianshu());
             preparedStatement.setString(5, A.getName());
             preparedStatement.setString(6, A.getId());
             preparedStatement.setString(7, A.getSex());
             preparedStatement.setString(8, A.getMinzu());
             preparedStatement.setString(9, A.getJiaoyuchengdu());
             preparedStatement.setString(10, name);
             System.out.println(A.getHubie());
             preparedStatement.executeUpdate();
             } catch (SQLException e) {
                // TODO Auto-generated catch block
               e.printStackTrace();
            }finally {

            }
    }
    public void showall(ArrayList<Information> people) throws ClassNotFoundException, SQLException{  //遍历整个数据库
        
         String sql1 ="select * from renkou";
    
         Connection connection = utils.getConnection();
             try {
                 PreparedStatement ps = connection.prepareStatement(sql1);
                 ResultSet rs =  ps.executeQuery();

             while(rs.next()) {
                 Information A = new Information();
                 A.setHubie(rs.getString(1));
                 A.setZhufangleixing(rs.getString(2));
                 A.setZhufangmianji(rs.getString(3));
                 A.setFangjianshu(rs.getString(4));
                 A.setName(rs.getString(5));
                 A.setId(rs.getString(6));
                 A.setSex(rs.getString(7));
                 A.setMinzu(rs.getString(8));
                 A.setJiaoyuchengdu(rs.getString(9));
                 people.add(A);
               }
             } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
       
   }
    public void select1(ArrayList<Information> people,String name) throws ClassNotFoundException, SQLException{
        System.out.println(name);
         String sql1 ="select * from renkou where name = ?";
                 //按名字查询
         Connection connection = utils.getConnection();
             try {
                 PreparedStatement ps = connection.prepareStatement(sql1);
                  ps.setString(1, name);
                 ResultSet rs =  ps.executeQuery();  
             while(rs.next()) {
                 Information A = new Information();
                 A.setHubie(rs.getString(1));
                 A.setZhufangleixing(rs.getString(2));
                 A.setZhufangmianji(rs.getString(3));
                 A.setFangjianshu(rs.getString(4));
                 A.setName(rs.getString(5));
                 A.setId(rs.getString(6));
                 A.setSex(rs.getString(7));
                 A.setMinzu(rs.getString(8));
                 A.setJiaoyuchengdu(rs.getString(9));
                 people.add(A);
               }
             } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
      
  }
    public void select3(ArrayList<Information> people,String sex) throws ClassNotFoundException, SQLException{
        //按性别查询
         String sql1 ="select * from renkou where sex = ?";
          //������䴫�����
         Connection connection = utils.getConnection();
             try {
                 PreparedStatement ps = connection.prepareStatement(sql1);
                  ps.setString(1, sex);
                 ResultSet rs =  ps.executeQuery();  
             while(rs.next()) {
                 Information A = new Information();
                 A.setHubie(rs.getString(1));
                 A.setZhufangleixing(rs.getString(2));
                 A.setZhufangmianji(rs.getString(3));
                 A.setFangjianshu(rs.getString(4));
                 A.setName(rs.getString(5));
                 A.setId(rs.getString(6));
                 A.setSex(rs.getString(7));
                 A.setMinzu(rs.getString(8));
                 A.setJiaoyuchengdu(rs.getString(9));
                 people.add(A);
               }
             } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
      
  }
    public void select4(ArrayList<Information> people,String minzu) throws ClassNotFoundException, SQLException{
        System.out.println(minzu);//�������ѯ
         String sql1 ="select * from renkou where minzu = ?";
          //按民族查询
         Connection connection = utils.getConnection();
             try {
                 PreparedStatement ps = connection.prepareStatement(sql1);
                  ps.setString(1,minzu);
                 ResultSet rs =  ps.executeQuery();  
             while(rs.next()) {
                 Information A = new Information();
                 A.setHubie(rs.getString(1));
                 A.setZhufangleixing(rs.getString(2));
                 A.setZhufangmianji(rs.getString(3));
                 A.setFangjianshu(rs.getString(4));
                 A.setName(rs.getString(5));
                 A.setId(rs.getString(6));
                 A.setSex(rs.getString(7));
                 A.setMinzu(rs.getString(8));
                 A.setJiaoyuchengdu(rs.getString(9));
                 people.add(A);
               }
             } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
      
  }
    public void select5(ArrayList<Information> people,String jiaoyuchengdu) throws ClassNotFoundException, SQLException{
        System.out.println(jiaoyuchengdu);//�������ѯ
         String sql1 ="select * from renkou where jiaoyuchengdu = ?";
          //按教育程度查询
         Connection connection = utils.getConnection();
             try {
                 PreparedStatement ps = connection.prepareStatement(sql1);
                  ps.setString(1,jiaoyuchengdu);
                 ResultSet rs =  ps.executeQuery();  
             while(rs.next()) {
                 Information A = new Information();
                 A.setHubie(rs.getString(1));
                 A.setZhufangleixing(rs.getString(2));
                 A.setZhufangmianji(rs.getString(3));
                 A.setFangjianshu(rs.getString(4));
                 A.setName(rs.getString(5));
                 A.setId(rs.getString(6));
                 A.setSex(rs.getString(7));
                 A.setMinzu(rs.getString(8));
                 A.setJiaoyuchengdu(rs.getString(9));
                 people.add(A);
               }
             } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
      
  }
    public void select2(ArrayList<Information> people,String id) throws ClassNotFoundException, SQLException{
        System.out.println(id);
         String sql1 ="select * from renkou where id = ?";
          //按身份证号查询
         Connection connection = utils.getConnection();
             try {
                 PreparedStatement ps = connection.prepareStatement(sql1);
                  ps.setString(1, id);
                 ResultSet rs =  ps.executeQuery();  
             while(rs.next()) {
                 Information A = new Information();
                 A.setHubie(rs.getString(1));
                 A.setZhufangleixing(rs.getString(2));
                 A.setZhufangmianji(rs.getString(3));
                 A.setFangjianshu(rs.getString(4));
                 A.setName(rs.getString(5));
                 A.setId(rs.getString(6));
                 A.setSex(rs.getString(7));
                 A.setMinzu(rs.getString(8));
                 A.setJiaoyuchengdu(rs.getString(9));
                 people.add(A);
               }
             } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
      
  }
    public void delite(String name) throws ClassNotFoundException, SQLException{         //删除
        Connection connection = utils.getConnection();
         String sql ="delete from renkou where name=?";
         PreparedStatement ps = connection.prepareStatement(sql);
         ps.setString(1, name);
         ps.executeUpdate();
                 
 }
}

com.Util包

utils.java(数据库工具类)

package com.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;



/**
 * JDBC��������
 */
public class utils {
    public static Connection getConnection() throws ClassNotFoundException, SQLException {
    
           Connection connection = null;
           PreparedStatement ps = null;
           ResultSet rs = null;
        Class.forName("com.mysql.cj.jdbc.Driver");
         connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db3","root", "1767737316.");
       return connection;
    }
    
    public static void close(Connection connection ) {
         try {
           if (connection != null) {
                connection.close();
             }
           
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
       }
     }
     public static void close(PreparedStatement preparedStatement ) {
         try {
            if (preparedStatement != null) {
                 preparedStatement.close();
             }            
        } catch (SQLException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
     public static void close(ResultSet resultSet ) {
        try {
            if (resultSet != null) {
                 resultSet.close();
             }
             
         } catch (SQLException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
     
 }

Servlet

addupdate.java(和添加和修改的html交互)

package Servlet;

import java.io.IOException;
import java.sql.SQLException;
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 com.Dao.Mannger;
import com.Bean.Information;
/**
 * Servlet implementation class addupdate
 */
@WebServlet("/addupdate")
public class addupdate extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public addupdate() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doPost(request, response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        request.setCharacterEncoding("utf-8");
        //设置相应的文本类型
        response.setContentType("text/html;charset=utf-8");//设置响应类型,并防止中文乱码
        Mannger A =new Mannger(); //dao层对象
        String name0 = request.getParameter("name0");//修改人口信息的名字
        String hubie = request.getParameter("hubie");
        String zhufangleixing = request.getParameter("zhufangleixing");
        String zhufangmianji = request.getParameter("zhufangmianji");
        String fangjianshu = request.getParameter("fangjianshu");
        String name = request.getParameter("name");
        String id = request.getParameter("id");
        String sex = request.getParameter("sex");
        String minzu = request.getParameter("minzu");
        String jiaoyuchengdu = request.getParameter("jiaoyuchengdu");
        String method = request.getParameter("method");   //html页面传来的字段名称,用来分类;
        Information B = new Information();    
        B.setHubie(hubie);
        B.setZhufangmianji(zhufangmianji);
        B.setZhufangleixing(zhufangleixing);
        B.setFangjianshu(fangjianshu);
        B.setName(name);
        B.setSex(sex);
        B.setId(id);
        B.setMinzu(minzu);
        B.setJiaoyuchengdu(jiaoyuchengdu);
        if("dengji".equals(method)) {
        try {
            A.add(B);
             
        } catch (ClassNotFoundException | SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        response.sendRedirect("showall.jsp");
        }
        if("update".equals(method)) {
            try {
                A.update(B,name0);
                 
            } catch (ClassNotFoundException | SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            response.sendRedirect("showall.jsp");
        }
        
    }
}

deliteselect.java(和删除查询html交互)

package Servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

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 com.Dao.Mannger;

import com.Bean.Information;
/**
 * Servlet implementation class delite
 */
@WebServlet("/deliteselect")
public class deliteselect extends HttpServlet {
    private static final long serialVersionUID = 1L;
    
    /**
     * @see HttpServlet#HttpServlet()
     */
    public deliteselect() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        
        request.setCharacterEncoding("utf-8");
        //设置相应的文本类型
        response.setContentType("text/html;charset=utf-8");//设置响应类型,并防止中文乱码
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        String xinxi = request.getParameter("xinxi");
        String  fangshi = request.getParameter("fangshi");  //html传来的value值  ,用来分类查询方式
        String method = request.getParameter("method");   //html传来的字段用来判断进入的函数
        ArrayList <Information> people = new ArrayList<Information>();
        //数据库工具类
        System.out.println(id);
        Mannger dao = new Mannger();
        if ("selectid".equals(method)) {
        if(id==null)
        {
            response.getWriter().append("输入内容为空");
        }else
        {
            try {
                dao.select2(people,id);
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            request.setAttribute("people",people);
            request.getRequestDispatcher("chakan.jsp").forward(request, response);    
       }
    }
        if("select4".equals(method)) {
            if("0".equals(fangshi))
            {      
                try {
                    dao.select1(people,xinxi);
                } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }   
                request.setAttribute("people",people);
                request.getRequestDispatcher("chakan.jsp").forward(request, response);
                 
            }
             if("1".equals(fangshi))    {
                    try {
                        dao.select3(people,xinxi);
                    } catch (ClassNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    request.setAttribute("people",people);
                    request.getRequestDispatcher("chakan.jsp").forward(request, response);
                }
             if("2".equals(fangshi))    {
                    try {
                        dao.select4(people,xinxi);
                    } catch (ClassNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    request.setAttribute("people",people);
                    request.getRequestDispatcher("chakan.jsp").forward(request, response);
                }
             if("3".equals(fangshi))    {
                    try {
                        dao.select5(people,xinxi);
                    } catch (ClassNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    request.setAttribute("people",people);
                    request.getRequestDispatcher("chakan.jsp").forward(request, response);
                }
        
        }
        if("delitechakan".equals(method)) {
            if(name==null)
            {
                response.getWriter().append("输入内容为空");
            }else
            {
                try {
                    dao.select1(people,name);
                } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                request.setAttribute("people",people);
                request.getRequestDispatcher("delite.jsp").forward(request, response);
                     
                try {
                    dao.delite(name);
                } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
    }
        }
        if("delite".equals(method)) {
            if(name==null){
                response.getWriter().append("不能输入为空");
            }else{
                
                try {
                    dao.delite(name);
                    response.getWriter().append("删除成功!");
                } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            
    }
        }

}

    
    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
}

 

 

下面是页面

home.html(主界面)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
                                    <h1 align = "center">欢迎使用人口普查系统</h1><br>
</head>
<body>

                  <div align = "center"> <a href="dengji.html   " >  登记人口信息></button ></a></div><br>                             
                <div align = "center"> <a href="update.html" >修改人口信息</button></a></div><br>
                <div align = "center">     <a href="delite.html   ">删除人口信息</button></a></div><br>
                <div align = "center"> <a href="select4.html">查询人口信息</button></a></div><br>
                <div align = "center">     <a href="showall.jsp">浏览人口信息</button></a></div><br>    

        </body>
    </html>            

dengji.html(登记信息页面)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>

<body>
<div id="addSubjectForm" align="center">
<form action="addupdate?method=dengji" method="post">
<tr>
<h2>请输入人口信息</h2>
</tr>

<table align="center"> 
<tr>
    <td>户别:</td>
     <td> 
 <input type="radio" name="hubie" value="集体户">集体户
 <input type="radio" name="hubie" value="家庭户" checked>家庭户

 </td>
    </tr>
    
    <tr>
    <td> 住房类型:</td>
        <td> 
 <input type="radio" name="zhufangleixing" value="家庭住宅">家庭住所 
 <input type="radio" name="zhufangleixing" value="集体住所" checked>集体住所
 <input type="radio" name="zhufangleixing" value="工作地住所">工作地住所
 <input type="radio" name="zhufangleixing" value="其他住宅">其他住宅
 <input type="radio" name="zhufangleixing" value="无住宅">无住宅
 </td>
    </tr>
    
    <tr>
    <td>本户现住房面积:</td>
    <td> 
     <input type="text" name="zhufangmianji" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')">平方米(只能输入整数)  
     </td> 
    </tr>
    
<tr>
    <td>本户现住房间数:</td>
    <td>
    <input type="text" name="fangjianshu" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')">间(只能输入整数)
    </td>
</tr>

<tr>

    <td>户主姓名:</td>
    <td>
    <input type="text" name="name">
    </td>
</tr>

<tr>
    <td>身份证号码:</td>
    <td>
    <input type="text" name="id" onblur="isCardNo(this.value)">
    </td>
</tr>

<tr>
    <td>性别:</td>
    <td>
     <input type="radio" name="sex" value="男">男
     <input type="radio" name="sex" value="女" checked>女
    </td>
</tr>

<tr>
    <td>民族:</td>
    <td>
    <input type="text" name="minzu">
    </td>
</tr>

<tr>
    <td>受教育程度:</td>
    <td>
     <select name="jiaoyuchengdu"> 
     <option value="研究生">研究生</option> 
     <option value="大学本科">大学本科</option> 
     <option value="大学专科">大学专科</option>
     <option value="高中" selected>高中</option> 
     <option value="初中">初中</option> 
     <option value="小学">小学</option> 
     <option value="未上过学">未上过学</option> 
      
     </select> 
    </td>
</tr>

<tr>
                      <td colspan="2"><div align="center">
                        <input type="submit" value="录入">    
                    </div>
                </td>
                  </tr>
                  </form>
                  </div>
                  
</body>
<script type="text/javascript">
function check()                        //封装一个<body>中做成点击事件的函数
{
    
    if($('input:radio[name="hubie"]:checked').val()==null) {
          alert('户别不能为空!');
          document.getElementById('hubie').focus();
          return false;
         }
    if($('input:radio[name="zhufangleixing"]:checked').val()==null) {
          alert('住房类型不能为空!');
          document.getElementById('zhufangleixing').focus();
          return false;
         }
    if($('input:radio[name="sex"]:checked').val()==null) {
          alert('性别不能为空!');
          document.getElementById('sex').focus();
          return false;
         }
    if(document.getElementById('zhufangmianji').value=='') {
          alert('现住房面积不能为空!');
          document.getElementById('zhufangmianji').focus();
          isInterger(classplace);
          return false;
         }
    
    if(document.getElementById('fangjianshu').value=='') {
          alert('现住房间数不能为空!');
          document.getElementById('fangjianshu').focus();
          return false;
         }
    
    if(document.getElementById('name').value=='') {
          alert('户主姓名不能为空!');
          document.getElementById('name').focus();
          return false;
         }
    
    
    if(document.getElementById('minzu').value=='') {
          alert('民族不能为空!');
          document.getElementById('minzu').focus();
          return false;
         }
     if(document.getElementById('jiaoyucengdu').value=='') {
          alert('受教育程度不能为空!');
          document.getElementById('jiaoyuchengdu').focus();
          return false;
         }
    return true;
}
function isCardNo(card) 
{ 
  // 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X 
  var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; 
  if(reg.test(card) === false) 
  { 
    alert("身份证输入不合法"); 
    document.getElementById('id').value="";
  } 
}
</script>
</html>

update.html(修改页面)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>

<body>
<div id="addSubjectForm" align="center">
<form action="addupdate?method=update" method="post">
<tr>
<h2>更改人口信息</h2>
</tr>
<td>户主姓名:</td>
    <td>
    <input type="text" name="name0">
    </td>
<table align="center"> 
<tr>
    <td>户别:</td>
     <td> 
 <input type="radio" name="hubie" value="集体户">集体户
 <input type="radio" name="hubie" value="家庭户" checked>家庭户

 </td>
    </tr>
    
    <tr>
    <td> 住房类型:</td>
        <td> 
 <input type="radio" name="zhufangleixing" value="家庭住宅">家庭住所 
 <input type="radio" name="zhufangleixing" value="集体住所" checked>集体住所
 <input type="radio" name="zhufangleixing" value="工作地住所">工作地住所
 <input type="radio" name="zhufangleixing" value="其他住宅">其他住宅
 <input type="radio" name="zhufangleixing" value="无住宅">无住宅
 </td>
    </tr>
    
    <tr>
    <td>本户现住房面积:</td>
    <td> 
     <input type="text" name="zhufangmianji" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')">平方米(只能输入整数)  
     </td> 
    </tr>

<tr>
    <td>本户现住房间数:</td>
    <td>
    <input type="text" name="fangjianshu" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')">间(只能输入整数)
    </td>
</tr>

<tr>

    <td>户主姓名:</td>
    <td>
    <input type="text" name="name">
    </td>
</tr>

<tr>
    <td>身份证号码:</td>
    <td>
    <input type="text" name="id" onblur="isCardNo(this.value)">
    </td>
</tr>

<tr>
    <td>性别:</td>
    <td>
     <input type="radio" name="sex" value="男">男
     <input type="radio" name="sex" value="女" checked>女
    </td>
</tr>

<tr>
    <td>民族:</td>
    <td>
    <input type="text" name="minzu">
    </td>
</tr>

<tr>
    <td>受教育程度:</td>
    <td>
     <select name="jiaoyuchengdu"> 
     <option value="研究生">研究生</option> 
     <option value="大学本科">大学本科</option> 
     <option value="大学专科">大学专科</option>
     <option value="高中" selected>高中</option> 
     <option value="初中">初中</option> 
     <option value="小学">小学</option> 
     <option value="未上过学">未上过学</option> 
      
     </select> 
    </td>
</tr>

<tr>
                      <td colspan="2"><div align="center">
                        <input type="submit" value="录入">    
                    </div>
                </td>
         </form>
                  </tr>
                 
                  </div>
                  
</body>
<script type="text/javascript">
function check()                        //封装一个<body>中做成点击事件的函数
{
    
    if($('input:radio[name="hubie"]:checked').val()==null) {
          alert('户别不能为空!');
          document.getElementById('hubie').focus();
          return false;
         }
    if($('input:radio[name="zhufangleixing"]:checked').val()==null) {
          alert('住房类型不能为空!');
          document.getElementById('zhufangleixing').focus();
          return false;
         }
    if($('input:radio[name="sex"]:checked').val()==null) {
          alert('性别不能为空!');
          document.getElementById('sex').focus();
          return false;
         }
    if(document.getElementById('zhufangmianji').value=='') {
          alert('现住房面积不能为空!');
          document.getElementById('zhufangmianji').focus();
          isInterger(classplace);
          return false;
         }
    
    if(document.getElementById('fangjianshu').value=='') {
          alert('现住房间数不能为空!');
          document.getElementById('fangjianshu').focus();
          return false;
         }
    
    if(document.getElementById('name').value=='') {
          alert('户主姓名不能为空!');
          document.getElementById('name').focus();
          return false;
         }
    
    
    if(document.getElementById('minzu').value=='') {
          alert('民族不能为空!');
          document.getElementById('minzu').focus();
          return false;
         }
     if(document.getElementById('jiaoyucengdu').value=='') {
          alert('受教育程度不能为空!');
          document.getElementById('jiaoyuchengdu').focus();
          return false;
         }
    return true;
}
function isCardNo(card) 
{ 
  // 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X 
  var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; 
  if(reg.test(card) === false) 
  { 
    alert("身份证输入不合法"); 
    document.getElementById('id').value="";
  } 
}
</script>
</html>

delite.html(删除)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div id="addSubjectForm" align="center">
<form action="deliteselect?method=delitechakan" method="post">
<h1>删除信息</h1>
<tr>
<h2>请输入户主姓名:</h2>
</tr>
<tr>
    <td>户主姓名:</td>
    <td><input type="text" name="name" size="20"></td>
 </tr>
   
        <tr>              
                      <td colspan="2"><div align="center">
                      <input type="submit" value="查看">   
                    </div>
                     </td>
          </tr>
                  </form>
                  </div>
</body>
</html>

delite.jsp(展示要删除的数据)

<%@page import="com.Dao.Mannger"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.Bean.Information"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>展示数据</title>
</head>
<body>
    <table border="1">
        <tr>
            <th>户别</th>
            <th>住房类型</th>
            <th>住房面积</th>
            <th>房间数</th>
            <th>户主姓名</th>
            <th>身份证号</th>
            <th>性别</th>
            <th>民族</th>
            <th>受教育程度</th>
        </tr>
        <%
        ArrayList <Information> B = (ArrayList<Information>) request.getAttribute("people");
        
            for (int i = 0; i < B.size(); i++) {
                Information A = B.get(i);    
                System.out.println(A.getFangjianshu());
        %>
        <tr>
            <td><%=A.getHubie()%></td>
            <td><%=A.getZhufangleixing()%></td>
            <td><%=A.getZhufangmianji()%></td>
            <td><%=A.getFangjianshu()%></td>
            <td><%=A.getName()%></td>
            <td><%=A.getId()%></td>
            <td><%=A.getSex()%></td>
            <td><%=A.getMinzu()%></td>
            <td><%=A.getJiaoyuchengdu()%></td>
        </tr>
 
        <%
            }
        %>
    <form action="deliteselect?method=delite" method="post">
    <input type="text" name="name" size="20">
    <input align = "center" type="submit" name="删除" value="删除"/>
        
        </form>
    </table>
</body>
</html>

select4.html(查询页面)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<head>
    <title>查询人口信息</title>
 
</head>

<body>
    <form action="deliteselect?method=select4" method="post">     //method为一个字段名,用来判断进入的方法
  
<input type="radio" name="fangshi" value="0">姓名
<input type="radio" name="fangshi" value="1">性别
<input type="radio" name="fangshi" value="2">民族
<input type="radio" name="fangshi" value="3">受教育程度

        <input  type="text" name="xinxi" >
        <input type="submit" value="查询">    
 
        <br />
        <br />

</form>
</body>

</html>

showall.jsp(遍历数据库所有数据信息)

<%@page import="com.Dao.Mannger"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.Bean.Information"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>展示数据</title>
</head>
<body>
    <table border="1">
        <tr>
            <th>户别</th>
            <th>住房类型</th>
            <th>住房面积</th>
            <th>房间数</th>
            <th>户主姓名</th>
            <th>身份证号</th>
            <th>性别</th>
            <th>民族</th>
            <th>受教育程度</th>
            <div>return Home ? <a href="home.html">home</a></div>
        </tr>
        <%
        ArrayList <Information> people = new ArrayList<Information>();
        Mannger dao = new Mannger();
            dao.showall(people);
            for (int i = 0; i < people.size(); i++) {
                Information A = people.get(i);    
        %>
        <tr>
            <td><%=A.getHubie()%></td>
            <td><%=A.getZhufangleixing()%></td>
            <td><%=A.getZhufangmianji()%></td>
            <td><%=A.getFangjianshu()%></td>
            <td> <%=A.getName()%></a></td>
            <td><a href ="/renkoupucahxitong/select?method=doPost&id=<%=A.getId()%>"><%=A.getId()%></td>
            <td><%=A.getSex()%></td>
            <td><%=A.getMinzu()%></td>
            <td><%=A.getJiaoyuchengdu()%></td>
        </tr>
 
        <%
            }
        %>
        
    </table>
</body>
</html>

chakan.jsp(查看身份证号跳转单人信息)

<%@page import="com.Dao.Mannger"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.Bean.Information"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>展示数据</title>
</head>
<body>
    <table border="1">
        <tr>
            <th>户别</th>
            <th>住房类型</th>
            <th>住房面积</th>
            <th>房间数</th>
            <th>户主姓名</th>
            <th>身份证号</th>
            <th>性别</th>
            <th>民族</th>
            <th>受教育程度</th>
            
        </tr>
        
        <%
        ArrayList <Information> B = (ArrayList<Information>) request.getAttribute("people");
        
            for (int i = 0; i < B.size(); i++) {
                Information A = B.get(i);    
                System.out.println(A.getFangjianshu());
        %>
        <tr>
            <td><%=A.getHubie()%></td>
            <td><%=A.getZhufangleixing()%></td>
            <td><%=A.getZhufangmianji()%></td>
            <td><%=A.getFangjianshu()%></td>
            <td><%=A.getName()%></td>
            <td><%=A.getId()%></td>
            <td><%=A.getSex()%></td>
            <td><%=A.getMinzu()%></td>
            <td><%=A.getJiaoyuchengdu()%></td>
        </tr>
 
        <%
            }
        %>
            
    </table>
    <div> return Home ? <a href="home.html">home</a></div>
</body>
</html>

到这里的话就结束了,如果有什么问题的话可以联系我1767737316@qq.com。

如果对你有帮助的希望能点个赞,欢迎转载!!!

 

上一篇:【RS-Defence】Adversarial Training on RS(附代码实现APR+LightGCN)


下一篇:Java JDBC