2020年11月18日
今天学习学姐的代码,遇到了400问题,代码没有错误,明天计划解决这个问题。
package 人口普查系统; public class Bean { private int id; private String hubie; private String livetype; private int area; private int roomnum; private String name; private String idcard; private String sex; private String nation; private String education; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getHubie() { return hubie; } public void setHubie(String hubie) { this.hubie = hubie; } public String getLivetype() { return livetype; } public void setLivetype(String livetype) { this.livetype = livetype; } public int getArea() { return area; } public void setArea(int area) { this.area = area; } public int getRoomnum() { return roomnum; } public void setRoomnum(int roomnum) { this.roomnum = roomnum; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getIdcard() { return idcard; } public void setIdcard(String idcard) { this.idcard = idcard; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getNation() { return nation; } public void setNation(String nation) { this.nation = nation; } public String getEducation() { return education; } public void setEducation(String education) { this.education = education; } public Bean(int id, String hubie, String livetype, int area, int roomnum, String name, String idcard,String sex, String nation, String education) { this.id = id; this.hubie = hubie; this.livetype = livetype; this.area = area; this.roomnum = roomnum; this.name = name; this.idcard = idcard; this.sex = sex; this.nation = nation; this.education = education; } public String toString() { return "Census{" + "id=" + id + ", hubie='" + hubie + '\'' + ", livetype='" + livetype + '\'' + ", area=" + area + ", roomnum=" + roomnum + ", name='" + name + '\'' + ", idcard='" + idcard + '\'' + ", sex='" + sex + '\'' + ", nation='" + nation + '\'' + ", education='" + education + '\'' + '}'; } }
package 人口普查系统; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; public class Dao {//dao层 private DBUtil dbutil=new DBUtil(); public Dao() { // TODO Auto-generated constructor stub } public boolean insert(Bean bean) {//插入数据的方法 boolean f=false; String sql="insert into person(id,hubie,livetype,area,roomnum, name, idcard, sex,nation, education) values('"+bean.getId()+"','"+bean.getHubie()+"','"+bean.getLivetype()+"','"+bean.getArea()+"','"+bean.getRoomnum()+"','"+bean.getName()+"','"+bean.getIdcard()+"','"+bean.getSex()+"','"+bean.getNation()+"','"+bean.getEducation()+"')"; Connection conn=DBUtil.getConnection();//数据库连接,加载驱动 Statement state=null; try { state=conn.createStatement();//实例化Statement对象,方便对sql语句进行操作 System.out.println(conn); state.executeUpdate(sql); f=true; //执行数据库更新操作用于执行INSERT、UPDATE或DELETE语句以及SQLDDL(数据定义语言)语句, //例如CREATETABLE和DROPTABLE,(创建表和删除表) }catch(Exception e)//当try语句中s出现异常时,会执行catch中的语句 { e.printStackTrace();//捕获异常的语句 } finally //finally作为异常处理的一部分,它只能用在try/catch语句中,并且附带一个语句块,表示这段语句最终一定会被执行(不管有没有抛出异常),经常被用在需要释放资源的情况下。 { DBUtil.close(conn); } return f; } public boolean delete(int id) {//删除方法 String sql="delete from person where id='"+id+"'"; boolean f=false; Connection conn =DBUtil.getConnection(); Statement st=null; try { st=conn.createStatement(); st.executeUpdate(sql); f=true; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ DBUtil.close(st, conn); } return f; } public boolean update(Bean bean) {//更新方法 String sql="update person set hubie='"+bean.getHubie()+"',livetype='"+bean.getLivetype()+"',area='"+bean.getArea()+"',roomnum='"+bean.getRoomnum()+"',name='"+bean.getName()+"',idcard='"+bean.getIdcard()+"',sex='"+bean.getSex()+"',nation='"+bean.getNation()+"',education='"+bean.getEducation()+"'where id='"+bean.getId()+"'"; Connection conn=DBUtil.getConnection(); boolean f=false; Statement st=null; try { st=conn.createStatement(); st.executeUpdate(sql); f=true; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return f; } public List<Bean> list(){//查询所有方法 String sql="select * from person order by id ASC"; Connection conn=DBUtil.getConnection(); Statement st=null; List<Bean> list=new ArrayList<>(); ResultSet rs=null; Bean bean=null; try { st=conn.createStatement(); st.executeQuery(sql); rs=st.executeQuery(sql); while(rs.next()) { int id=rs.getInt("id"); String hubie = rs.getString("hubie"); String livetype = rs.getString("livetype"); int area=rs.getInt("area"); int roomnum=rs.getInt("roomnum"); String name = rs.getString("name"); String idcard=rs.getString("idcard"); String sex = rs.getString("sex"); String nation = rs.getString("nation"); String education = rs.getString("education"); bean=new Bean(id,hubie,livetype,area,roomnum, name, idcard, sex,nation, education); list.add(bean); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { DBUtil.close(rs, st, conn); } return list; } public List<Bean> searchByName(String str) throws SQLException{//查询条件方法 String sql="select * from person where(name like '%"+str+"%')"; Connection conn=DBUtil.getConnection(); Statement st=null; PreparedStatement pt = conn.prepareStatement(sql); List<Bean> list=new ArrayList<>(); ResultSet rs=null; Bean bean=null; try { pt=conn.prepareStatement(sql); rs=pt.executeQuery(); while(rs.next()) { int id=rs.getInt("id"); String hubie = rs.getString("hubie"); String livetype = rs.getString("livetype"); int area=rs.getInt("area"); int roomnum=rs.getInt("roomnum"); String name = rs.getString("name"); String idcard=rs.getString("idcard"); String sex = rs.getString("sex"); String nation = rs.getString("nation"); String education = rs.getString("education"); bean=new Bean(id,hubie,livetype,area,roomnum, name, idcard, sex,nation, education); list.add(bean); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { DBUtil.close(rs, st, conn); } return list; } public List<Bean> searchBySex(String str) throws SQLException{//查询条件方法 String sql="select * from person where(sex like '%"+str+"%')"; Connection conn=DBUtil.getConnection(); Statement st=null; PreparedStatement pt = conn.prepareStatement(sql); List<Bean> search=new ArrayList<>(); ResultSet rs=null; Bean bean=null; try { pt=conn.prepareStatement(sql); rs=pt.executeQuery(); while(rs.next()) { int id=rs.getInt("id"); String hubie = rs.getString("hubie"); String livetype = rs.getString("livetype"); int area=rs.getInt("area"); int roomnum=rs.getInt("roomnum"); String name = rs.getString("name"); String idcard=rs.getString("idcard"); String sex = rs.getString("sex"); String nation = rs.getString("nation"); String education = rs.getString("education"); bean=new Bean(id,hubie,livetype,area,roomnum, name, idcard, sex,nation, education); search.add(bean); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { DBUtil.close(rs, st, conn); } return search; } public List<Bean> searchByEducation(String str) throws SQLException{//查询条件方法 String sql="select * from person where(education like '%"+str+"%')"; Connection conn=DBUtil.getConnection(); Statement st=null; PreparedStatement pt = conn.prepareStatement(sql); List<Bean> search=new ArrayList<>(); ResultSet rs=null; Bean bean=null; try { pt=conn.prepareStatement(sql); rs=pt.executeQuery(); while(rs.next()) { int id=rs.getInt("id"); String hubie = rs.getString("hubie"); String livetype = rs.getString("livetype"); int area=rs.getInt("area"); int roomnum=rs.getInt("roomnum"); String name = rs.getString("name"); String idcard=rs.getString("idcard"); String sex = rs.getString("sex"); String nation = rs.getString("nation"); String education = rs.getString("education"); bean=new Bean(id,hubie,livetype,area,roomnum, name, idcard, sex,nation, education); search.add(bean); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { DBUtil.close(rs, st, conn); } return search; } public List<Bean> searchByNation(String str) throws SQLException{//查询条件方法 String sql="select * from person where(nation like '%"+str+"%')"; Connection conn=DBUtil.getConnection(); Statement st=null; PreparedStatement pt = conn.prepareStatement(sql); List<Bean> search=new ArrayList<>(); ResultSet rs=null; Bean bean=null; try { pt=conn.prepareStatement(sql); rs=pt.executeQuery(); while(rs.next()) { int id=rs.getInt("id"); String hubie = rs.getString("hubie"); String livetype = rs.getString("livetype"); int area=rs.getInt("area"); int roomnum=rs.getInt("roomnum"); String name = rs.getString("name"); String idcard=rs.getString("idcard"); String sex = rs.getString("sex"); String nation = rs.getString("nation"); String education = rs.getString("education"); bean=new Bean(id,hubie,livetype,area,roomnum, name, idcard, sex,nation, education); search.add(bean); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { DBUtil.close(rs, st, conn); } return search; } }
package 人口普查系统; 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 { private static String url = "jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf8"; private static String user = "root"; private static String password = "789987"; private static String jdbcName="com.mysql.jdbc.Driver"; private Connection con=null; public static Connection getConnection() { Connection con=null; try { Class.forName(jdbcName); con=DriverManager.getConnection(url, user, password); //System.out.println("数据库连接成功"); } catch (Exception e) { // TODO Auto-generated catch block //System.out.println("数据库连接失败"); e.printStackTrace(); } try { con = DriverManager.getConnection(url,user,password); System.out.println("连接成功"); } catch (SQLException e) { // TODO: handle exception e.printStackTrace(); } return con; } public static void main(String[] args)throws SQLException { Connection conn = getConnection(); PreparedStatement pstmt = null; ResultSet rs = null; String sql ="select * from person"; pstmt = conn.prepareStatement(sql); rs = pstmt.executeQuery(); System.out.println(getConnection()); while(rs.next()){ System.out.println("成功"); } } // return con; public static void close(Connection con) { if(con!=null) try { con.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 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(); } } } }
package 人口普查系统; import java.io.IOException; import java.sql.SQLException; 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; /** * Servlet implementation class searchServlet */ @WebServlet("/searchServlet") public class searchServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public searchServlet() { 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 // response.getWriter().append("Served at: ").append(request.getContextPath()); request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); String cxfs = request.getParameter("cxfs"); System.out.print(cxfs); String str = request.getParameter("value"); Dao dao = new Dao(); List<Bean> list = null; try { if ("1".equals(cxfs)) { list = dao.searchByName(str); } if ("2".equals(cxfs)) { list = dao.searchBySex(str); } if ("3".equals(cxfs)) { list = dao.searchByEducation(str); } if ("4".equals(cxfs)) { list = dao.searchByNation(str); } } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } request.setAttribute("list", list); request.getRequestDispatcher("list.jsp").forward(request, response); System.out.print(list.size()); } /** * @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); } }
package 人口普查系统; import java.io.IOException; import java.io.UnsupportedEncodingException; 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; /** * Servlet implementation class servlet */ @WebServlet("/servlet") public class servlet extends HttpServlet { Dao dao=new Dao(); private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public servlet() { super(); // TODO Auto-generated constructor stub } private void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub request.setCharacterEncoding("utf-8"); int id = Integer.parseInt(request.getParameter("id")); String hubie = request.getParameter("hubie"); String livetype = request.getParameter("livetype"); int area= Integer.parseInt(request.getParameter("area")); int roomnum = Integer.parseInt(request.getParameter("roomnum")); String name = request.getParameter("name"); String idcard = request.getParameter("idcard"); String sex = request.getParameter("sex"); String nation = request.getParameter("nation"); String education= request.getParameter("education"); Bean bean=new Bean(id,hubie,livetype,area,roomnum,name,idcard,sex,nation,education); dao.update(bean); request.setAttribute("message", "修改成功"); request.getRequestDispatcher("servlet?method=list").forward(request, response); } private void list(HttpServletRequest request, HttpServletResponse response) throws Exception { // TODO Auto-generated method stub request.setCharacterEncoding("utf-8"); List<Bean> list = dao.list(); request.setAttribute("list", list); request.getRequestDispatcher("list.jsp").forward(request,response); } private void delete(HttpServletRequest request, HttpServletResponse response) throws Exception, IOException { // TODO Auto-generated method stub request.setCharacterEncoding("UTF-8"); int id=Integer.parseInt(request.getParameter("id")); dao.delete(id); //进行数据库的删除操作 request.setAttribute("message", "删除成功"); request.getRequestDispatcher("servlet?method=list").forward(request, response); } private void insert(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // TODO Auto-generated method stub request.setCharacterEncoding("utf-8"); int id = Integer.parseInt(request.getParameter("id")); String hubie = request.getParameter("hubie"); String livetype = request.getParameter("livetype"); int area= Integer.parseInt(request.getParameter("area")); int roomnum = Integer.parseInt(request.getParameter("roomnum")); String name = request.getParameter("name"); String idcard = request.getParameter("idcard"); String sex = request.getParameter("sex"); String nation = request.getParameter("nation"); String education= request.getParameter("education"); Bean bean=new Bean(id,hubie,livetype,area,roomnum, name, idcard, sex,nation, education); if(dao.insert(bean)) { request.setAttribute("message", "添加成功"); request.getRequestDispatcher("index.jsp").forward(request, response); } } private void search(HttpServletRequest request, HttpServletResponse response) throws Exception, IOException { // TODO Auto-generated method stub request.setCharacterEncoding("UTF-8"); String cxfs = request.getParameter("cxfs"); System.out.print("cxfs"); request.setAttribute("search", "查询成功"); request.getRequestDispatcher("list.jsp").forward(request, response); } private void fanglist(HttpServletRequest request, HttpServletResponse response) throws Exception { // TODO Auto-generated method stub request.setCharacterEncoding("utf-8"); List<Bean> list = dao.list(); request.setAttribute("list", list); request.getRequestDispatcher("list.jsp").forward(request,response); } /** * @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"); String method=request.getParameter("method"); if("insert".equals(method)) { insert(request,response); } else if("delete".equals(method)) { try { delete(request,response); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if("update".equals(method)) { update(request,response); } else if("list".equals(method)) { try { list(request,response); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }} else if("search".equals(method)) { try { search(request,response); } catch (Exception 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); } }
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>人口普查系统</title> <style type="text/css"> a{font-size:30px} </style> </head> <body><% Object message =request.getAttribute("message"); if(message!=null&&!"".equals(message)){ %> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%}%> <div align="center" font-size="30px"> <h1>人口普查系统</h1> <div> <a href="insert.jsp">信息登记</a> </div> <div> <a href="servlet?method=list">信息修改</a> </div> <div> <a href="servlet?method=list">信息删除</a> </div> <div> <a href="servlet?method=list">浏览信息</a> </div> <div> <a href="servlet?method=list">查询信息</a> </div> </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> <% Object message = request.getAttribute("message"); if (message != null && !"".equals(message)) { %> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); //弹出对话框 </script> <% } %> <div align="center"> <h1>添加信息</h1> <a href="index.jsp">返回主页</a> <form action="servlet?method=insert" method="post"> <table id="addTable" class="table table-bordered "> <tr class="text-center row"> <tr> <td class="col-sm-2"> id </td> <td class="col-sm-4"> <input type="text" class="form-control" name="id" id="id" > </td> <tr class="text-center row"> <td class="col-sm-2"> 户别 </td> <td class="col-sm-4"> <input type="radio" name="hubie" id="hubie" value="家庭户">家庭户 <input type="radio" name="hubie" id="hubie" value="集体户">集体户 </td></tr> <tr> <td class="col-sm-2"> 住房类型 </td> <td class="col-sm-4"> <input type="radio" name="livetype" id="livetype" value="家庭住宅">家庭住宅 <input type="radio" name="livetype" id="livetype" value="集体住所">集体住所 </td><tr><td> </td><td> <input type="radio" name="livetype" id="livetype" value="工作地住所">工作地住所 <input type="radio" name="livetype" id="livetype" value="其他住宅">其他住宅 <input type="radio" name="livetype" id="livetype" value="无住宅">无住宅 </td> </tr> <tr class="text-center row"> <td class="col-sm-2"> 本户现住房面积: </td> <td class="col-sm-4"> <input type="text" class="form-control" name="area" id="area" placeholder="请输入数字(平方米)"> </td> </tr> <tr> <td class="col-sm-2 "> 本户现住房间数: </td> <td class="col-sm-4"> <input type="text" class="form-control" name="roomnum" id="roomnum" placeholder="请输入数字(间)"> </td> </tr> <tr class="text-center row"> <td class="col-sm-2"> 户主姓名 </td> <td class="col-sm-4"> <input type="text" class="form-control" name="name" id="name" placeholder="请输入户主姓名"> </td> </tr> <tr class="text-center row"> <td class="col-sm-2 "> 身份证号码 </td> <td class="col-sm-4"> <input type="text" class="form-control" name="idcard" id="idcard" placeholder="请输入身份证号码"> </td> </tr> <tr class="text-center row"> <td class="col-sm-2"> 性别 </td> <td class="col-sm-4"> <input type="radio" name="sex" id="sex" value="男">男 <input type="radio" name="sex" id="sex" value="女">女 </td> </tr> <tr class="text-center row"> <td class="col-sm-2"> 民族 </td> <td class="col-sm-4"> <input type="text" class="form-control" name="nation" id="nation" placeholder="民族"> </td> </tr> <tr class="text-center row"> <td> 受教育程度 </td> <td colspan="3"> <select class="form-control" id="education" name="education"> <option value="研究生">研究生</option> <option value="大学本科">大学本科</option> <option value="大学专科">大学专科</option> <option value="高中">高中</option> <option value="初中">初中</option> <option value="小学">小学</option> <option value="未上过学">未上过学</option> </select> </td> </tr> </table> <input type="submit" value="添加" onclick= "return check()" /> </form> </div> </body> <script type="text/javascript"> function check() //封装一个<body>中做成点击事件的函数 { if(document.getElementById('area').value=='') { alert('现住房面积不能为空!'); document.getElementById('area').focus(); return false; } else if(document.getElementById('area').value%1!=0){ alert('住房面积不是整数!'); return false; } if(document.getElementById('roomnum').value=='') { alert('现住房间数不能为空!'); document.getElementById('roomnum').focus(); return false; } else if(document.getElementById('roomnum').value%1!=0){ alert('现住房间数不是整数!'); return false; } if(document.getElementById('name').value=='') { alert('户主姓名不能为空!'); document.getElementById('name').focus(); return false; } if(document.getElementById('idcard').value.length!=18) { alert('身份证号码位数错误!'); document.getElementById('idcard').focus(); return false; } if(document.getElementById('nation').value=='') { alert('民族不能为空!'); document.getElementById('nation').focus(); return false; } } </script> </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"); Object grade_list = request.getAttribute("grade_list"); if(message!=null && !"".equals(message)){ %> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%} %> <div align="center"> <h1 >信息列表</h1> <h1> <form action="searchServlet" method="post"> <select name="cxfs"> <option id="cxfs"value ="1">姓名</option> <option id="cxfs" value ="2">性别</option> <option id="cxfs"value="3">受教育程度</option> <option id="cxfs"value="4" >民族</option> </select> <input type="text" id="value" name="value" placeholder="请输入条件"> <input type="submit" id="select" name="select" value="查询" /> </form> </h1> <a href="index.jsp">返回主页</a> <table > <tr> <td>id</td> <td>户别</td> <td>住房类型</td> <td>面积</td> <td>数目</td> <td>姓名</td> <td>身份证</td> <td>性别</td> <td>民族</td> <td>教育</td> <td align="center" colspan="2">操作</td> </tr> <c:forEach items="${list}" var="item"> <tr> <td>${item.id}</td> <td>${item.id}</td> <td>${item.hubie}</td> <td>${item.livetype}</td> <td>${item.area}</td> <td>${item.roomnum}</td> <td>${item.name}</td> <td>${item.idcard}</td> <td>${item.sex}</td> <td>${item.nation}</td> <td>${item.education}</td> <td><a href="update.jsp?id=${item.id}&hubie=${item.hubie}&livetype=${item.livetype}&area=${item.area}&roomnum=${item.roomnum}&name=${item.name}&idcard=${item.idcard}&sex=${item.sex}&nation=${item.nation}&education=${item.education}">修改</a></td> <td><a href="servlet?method=delete&id=${item.id}">删除</a></td> </tr> </c:forEach> </table> </div> </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"); Object grade_list = request.getAttribute("grade_list"); if(message!=null && !"".equals(message)){ %> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%} %> <div align="center"> <h1 >信息列表</h1> <h1> <form action="searchServlet" method="post"> <select name="cxfs"> <option id="cxfs"value ="1">姓名</option> <option id="cxfs" value ="2">性别</option> <option id="cxfs"value="3">受教育程度</option> <option id="cxfs"value="4" >民族</option> </select> <input type="text" id="value" name="value" placeholder="请输入条件"> <input type="submit" id="select" name="select" value="查询" /> </form> </h1> <a href="index.jsp">返回主页</a> <table > <tr> <td>id</td> <td>户别</td> <td>住房类型</td> <td>面积</td> <td>数目</td> <td>姓名</td> <td>身份证</td> <td>性别</td> <td>民族</td> <td>教育</td> <td align="center" colspan="2">操作</td> </tr> <c:forEach items="${list}" var="item"> <tr> <td>${item.id}</td> <td>${item.id}</td> <td>${item.hubie}</td> <td>${item.livetype}</td> <td>${item.area}</td> <td>${item.roomnum}</td> <td>${item.name}</td> <td>${item.idcard}</td> <td>${item.sex}</td> <td>${item.nation}</td> <td>${item.education}</td> <td><a href="update.jsp?id=${item.id}&hubie=${item.hubie}&livetype=${item.livetype}&area=${item.area}&roomnum=${item.roomnum}&name=${item.name}&idcard=${item.idcard}&sex=${item.sex}&nation=${item.nation}&education=${item.education}">修改</a></td> <td><a href="servlet?method=delete&id=${item.id}">删除</a></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>修改</h1> <a href="index.jsp">返回主页</a> <form action="servlet?method=update" method="post"> <div> id:<input type="text" id="id" name="id" readonly="true" value="${param.id}" /> </div> <div> 户别: <input type="radio" name="hubie" id="hubie" value="家庭户">家庭户 <input type="radio" name="hubie" id="hubie" value="集体户">集体户 </div> <div> 住房类型:<input type="text" id="livetype" name="livetype" value="${param.livetype}" /> </div> <div> 面积:<input type="text" id="area" name="area" value="${param.area}" /> </div> <div> 数目:<input type="text" id="roomnum" name="roomnum" value="${param.roomnum}" /> </div> <div> 姓名:<input type="text" id="name" name="name" value="${param.name}" /> </div> <div> 身份证:<input type="text" id="idcard" name="idcard" value="${param.idcard}" /> </div> <div> 性别:<input type="radio" id="sex" name=sex value="男" />男 <input type="radio" id="sex" name="sex" value="女" />女 </div> <div> 民族:<input type="text" id="nation" name="nation" value="${param.nation}" /> </div> <div> 教育:<select class="form-control" id="education" name="education" check="${param.education}"> <option value="研究生">研究生</option> <option value="大学本科">大学本科</option> <option value="大学专科">大学专科</option> <option value="高中">高中</option> <option value="初中">初中</option> <option value="小学">小学</option> <option value="未上过学">未上过学</option> </select> </div> <div> <input type="submit" value="修改" onclick= "return check()" /> </div> </form> </div> </body> <script type="text/javascript"> function check() //封装一个<body>中做成点击事件的函数 { if(document.getElementById('area').value=='') { alert('现住房面积不能为空!'); document.getElementById('area').focus(); isInterger(area); return false; } else if(document.getElementById('area').value%1!=0){ alert('住房面积不是整数!'); return false; } if(document.getElementById('roomnum').value=='') { alert('现住房间数不能为空!'); document.getElementById('roomnum').focus(); return false; } else if(document.getElementById('roomnum').value%1!=0){ alert('现住房间数不是整数!'); return false; } if(document.getElementById('idcard').value.length!=18) { alert('身份证号码位数错误!'); document.getElementById('idcard').focus(); return false; } } </script> </html>