人口普查系統的要求已經在前面的博客里面發了,這是我用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。
如果對你有幫助的希望能點個贊,歡迎轉載!!!