本次是JavaWeb期中考试最后一个部分,系统更新和数据显示的代码分享
首先是updateq.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>更新前端界面</title> </head> <body> <form action="update.jsp" method="get"> <table align ="center" boder="1" width="500"> <tr> <td>姓名:</td> <td><input type="text" name="xingming" /></td> </tr> <tr> <tr align "center"> <td colspan="2"><input type ="submit" value ="更新"/> </td> </tr> </table> </form> </body>
update.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="R.Renkou"%> <%@ page import="Dao.dao"%> <%@ page import="java.util.ArrayList"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>请确认您要更新的信息</title> </head> <body> <% ArrayList<Renkou>a1=new ArrayList<Renkou>(); dao d=new dao(); String xname=request.getParameter("xingming"); session.setAttribute("name", xname); a1=d.searchbyname(xname); %> <table border="1" width="100%"> <tr> <th>户别</th> <th>类型</th> <th>面积</th> <th>房间数</th> <th>户主姓名</th> <th>身份证号</th> <th>性别</th> <th>民族</th> <th>受教育程度</th> </tr> <% for(int i=0;i<a1.size();i++) { Renkou in=a1.get(i); String hubie=in.Gethubie(); String leixing=in.Getleixing(); String mianji=in.Getmianji(); String fangjianshu=in.Getfangjianshu(); String xingming2=in.Getxingming(); String shenfenzhenghao=in.Getshenfenzhenghao(); String xingbie2=in.Getxingbie(); String minzu2=in.Getminzu(); String jiaoyu2=in.Getjiaoyu(); %> <tr> <td><%=(hubie) %></td> <td><%=(leixing) %></td> <td><%=(mianji) %></td> <td><%=(fangjianshu) %></td> <td><%=(xingming2) %></td> <td><%=(shenfenzhenghao) %></td> <td><%=(xingbie2) %></td> <td><%=(minzu2) %></td> <td><%=(jiaoyu2) %></td> </tr> <% } %> </table> <input style="margin-left:230px;margin-top:90px;width:150px;height:60px" type = "button" value = "取消更新点击这里" onclick = "window.location.href ='index.jsp'"> <input style="margin-left:230px;margin-top:90px;width:150px;height:60px" type = "button" value = "确认更新请点击这里" onclick = "window.location.href ='querenxiugaiq.jsp'">
querenxiugaiq.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>修改界面</title> </head> <body> <form action="querenxiugai.jsp" method="get"> <table align ="center" boder="1" width="500"> <tr> <td>姓名(修改前):</td> <td><input type="text" name="yname" /></td> </tr> <tr> <td>身份证号码(修改后):</td> <td><input type="text" name="shenfenzheng1" /></td> </tr> <tr> <td>性别(修改后):</td> <td><input type ="text" name="upsex"/></td> </tr> <tr> <td>民族(修改后):</td> <td><input type ="text" name="upminzu"/></td> </tr> <tr> <td>受教育程度(修改后):</td> <td><input type ="text" name="upjiaoyu"/></td> </tr> <tr align "center"> <td colspan="2"><input type ="submit" value ="确认修改"/> </td> </tr> </table> </form> </body>
querenxiugai.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="R.Renkou"%> <%@ page import="Dao.dao"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% //以下语句用于接收客户端传来的参数 dao d=new dao(); Renkou r=new Renkou(); String yname=request.getParameter("yname"); String shenfenzheng1 =request.getParameter("shenfenzheng1"); String upsex=request.getParameter("upsex"); String upminzu =request.getParameter("upminzu"); String upjiaoyu=request.getParameter("upjiaoyu"); d.judge(shenfenzheng1); if(d.judge(shenfenzheng1)==0) { response.getWriter().append("身份证号输入不正确!"); %><input type="button" onclick="window.location.href ='querenxiugai.jsp'" value="重新输入"/> <% } d.update(shenfenzheng1,upsex,upminzu,upjiaoyu,yname); %> <input style="margin-left:230px;margin-top:90px;width:100px;height:60px" type = "button" value = "点击这里返回" onclick = "window.location.href = 'index.jsp'"> </body> </html>
show.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="R.Renkou"%> <%@ page import="java.util.ArrayList"%> <%@ page import="Dao.dao"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% dao d=new dao(); ArrayList<Renkou> r=new ArrayList<Renkou>(); r=d.show(); %> <table border="1" width="100%"> <tr> <th>户别</th> <th>类型</th> <th>面积</th> <th>房间数</th> <th>户主姓名</th> <th>身份证号</th> <th>性别</th> <th>民族</th> <th>受教育程度</th> </tr> <% for(int i=0;i<r.size();i++) { Renkou in=r.get(i); String hubie=in.Gethubie(); String leixing=in.Getleixing(); String mianji=in.Getmianji(); String fangjianshu=in.Getfangjianshu(); String xingming2=in.Getxingming(); String shenfenzhenghao=in.Getshenfenzhenghao(); String xingbie2=in.Getxingbie(); String minzu2=in.Getminzu(); String jiaoyu2=in.Getjiaoyu(); %> <tr> <td><%=(hubie) %></td> <td><%=(leixing) %></td> <td><%=(mianji) %></td> <td><%=(fangjianshu) %></td> <td><%=(xingming2) %></td> <td><%=(shenfenzhenghao) %></td> <td><%=(xingbie2) %></td> <td><%=(minzu2) %></td> <td><%=(jiaoyu2) %></td> </tr> <% } %> </table> <input style="margin-left:230px;margin-top:90px;width:100px;height:60px" type = "button" value = "返回主菜单" onclick = "window.location.href = 'index.jsp'"> </body> </html>
标签:JavaWeb,期中考试,修改,jsp,new,2019,xname From: https://www.cnblogs.com/Arkiya/p/16851550.html