前台的代码全部来源于书上第十章,部分代码因为执行有误所以进行了修改。
(一)注册
HandleRegister.servlet
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException { String uri="jdbc:mysql://127.0.0.1/mobileshop?"+ "user=root&password=J123456&characterEncoding=gb2312"; Connection con; PreparedStatement sql; Register userBean=new Register(); //创建的Javabean模型 request.setAttribute("userBean",userBean); String logname=request.getParameter("logname").trim(); String password=request.getParameter("password").trim(); String again_password=request.getParameter("again_password").trim(); String phone=request.getParameter("phone").trim(); String address=request.getParameter("address").trim(); String realname=request.getParameter("realname").trim(); if(logname==null) logname=""; if(password==null) password=""; if(!password.equals(again_password)) { userBean.setBackNews("两次密码不同,注册失败,"); RequestDispatcher dispatcher= request.getRequestDispatcher("inputRegisterMess.jsp"); dispatcher.forward(request, response);//转发 return; } boolean isLD=true; for(int i=0;i<logname.length();i++){ char c=logname.charAt(i); if(!((c<='z'&&c>='a')||(c<='Z'&&c>='A')||(c<='9'&&c>='0'))) isLD=false; } boolean boo=logname.length()>0&&password.length()>0&&isLD; String backNews=""; try{ con=DriverManager.getConnection(uri); String insertCondition="INSERT INTO user VALUES (?,?,?,?,?)"; sql=con.prepareStatement(insertCondition); if(boo) { sql.setString(1,handleString(logname)); sql.setString(2,handleString(password)); sql.setString(3,handleString(phone)); sql.setString(4,handleString(address)); sql.setString(5,handleString(realname)); int m=sql.executeUpdate(); if(m!=0){ backNews="注册成功"; userBean.setBackNews(backNews); userBean.setLogname(logname); userBean.setPhone(handleString(phone)); userBean.setAddress(handleString(address)); userBean.setRealname(handleString(realname)); } } else { backNews="信息填写不完整或名字中有非法字符"; userBean.setBackNews(backNews); } con.close(); } catch(SQLException exp){ backNews="该会员名已被使用,请您更换名字"+exp; userBean.setBackNews(backNews); } RequestDispatcher dispatcher= request.getRequestDispatcher("inputRegisterMess.jsp"); dispatcher.forward(request, response);//转发 }(二)登录
HandleLogin.servlet
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ Connection con; Statement sql; String logname=request.getParameter("logname").trim(), password=request.getParameter("password").trim(); logname=handleString(logname); password=handleString(password); String uri="jdbc:mysql://127.0.0.1/mobileshop?"+ "user=root&password=J123456&characterEncoding=gb2312"; boolean boo=(logname.length()>0)&&(password.length()>0); try{ con=DriverManager.getConnection(uri); String condition="select * from user where logname = '"+logname+ "' and password ='"+password+"'"; sql=con.createStatement(); if(boo){ ResultSet rs=sql.executeQuery(condition); boolean m=rs.next(); if(m==true){ //调用登录成功的方法: success(request,response,logname,password); RequestDispatcher dispatcher= request.getRequestDispatcher("login.jsp");//转发 dispatcher.forward(request,response); } else{ String backNews="您输入的用户名不存在,或密码不般配"; //调用登录失败的方法: fail(request,response,logname,backNews); } } else{ String backNews="请输入用户名和密码"; fail(request,response,logname,backNews); } con.close(); } catch(SQLException exp){ String backNews=""+exp; fail(request,response,logname,backNews); } } public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ doPost(request,response); } public void success(HttpServletRequest request,HttpServletResponse response ,String logname,String password) { Login loginBean=null; HttpSession session=request.getSession(true); try{ loginBean=(Login)session.getAttribute("loginBean"); if(loginBean==null){ loginBean=new Login(); //创建新的数据模型 session.setAttribute("loginBean",loginBean); loginBean=(Login)session.getAttribute("loginBean"); } String name =loginBean.getLogname(); if(name.equals(logname)) { loginBean.setBackNews(logname+"已经登录了"); loginBean.setLogname(logname); } else { //数据模型存储新的登录用户 loginBean.setBackNews(logname+"登录成功"); loginBean.setLogname(logname); } } catch(Exception ee){ loginBean=new Login(); session.setAttribute("loginBean",loginBean); loginBean.setBackNews(logname+"登录成功"); loginBean.setLogname(logname); } }(三)浏览手机
QueryAllRecord.java public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ request.setCharacterEncoding("gb2312"); String idNumber= request.getParameter("fenleiNumber"); if(idNumber==null) idNumber="0"; int id = Integer.parseInt(idNumber); HttpSession session=request.getSession(true); Connection con=null; DataByPage dataBean=null; try{ dataBean=(DataByPage)session.getAttribute("dataBean"); if(dataBean==null){ dataBean=new DataByPage(); //创建Javabean对象 session.setAttribute("dataBean",dataBean); } } catch(Exception exp){ dataBean=new DataByPage(); session.setAttribute("dataBean",dataBean); } String uri="jdbc:mysql://127.0.0.1/mobileshop"; try{ con=DriverManager.getConnection(uri,"root","J123456"); Statement sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs=sql.executeQuery("SELECT * FROM mobileForm where id = "+id); rowSet=new CachedRowSetImpl(); //创建行集对象 rowSet.populate(rs); dataBean.setRowSet(rowSet); //行集数据存储在dataBean中 con.close(); //关闭连接 } catch(SQLException exp){} response.sendRedirect("byPageShow.jsp");//重定向到byPageShow.jsp }
查看细节和加入购物车需要先登录
lookmobile.jsp <% try { Class.forName("com.mysql.jdbc.Driver"); } catch(Exception e){} String uri="jdbc:mysql://127.0.0.1/mobileshop?"+ "user=root&password=J123456&characterEncoding=gb2312"; Connection con; Statement sql; ResultSet rs; try { con=DriverManager.getConnection(uri); sql=con.createStatement(); //读取mobileClassify表,获得分类: rs=sql.executeQuery("SELECT * FROM mobileClassify "); out.print("<form action='queryServlet' method ='post'>") ; out.print("<select name='fenleiNumber'>") ; while(rs.next()){ int id = rs.getInt(1); String mobileCategory = rs.getString(2); out.print("<option value ="+id+">"+mobileCategory+"</option>"); } out.print("</select>"); out.print("<input type ='submit' value ='提交'>"); out.print("</form>"); con.close(); } catch(SQLException e){ out.print(e); } %> showdetail.jsp <% if(loginBean==null){ response.sendRedirect("login.jsp");//重定向到登录页面 } else { boolean b =loginBean.getLogname()==null|| loginBean.getLogname().length()==0; if(b) response.sendRedirect("login.jsp");//重定向到登录页面 } String mobileID = request.getParameter("xijie"); out.print("<th>产品号"+mobileID); if(mobileID==null) { out.print("没有产品号,无法查看细节"); return; } Connection con; Statement sql; ResultSet rs; try { Class.forName("com.mysql.jdbc.Driver"); } catch(Exception e){} String uri="jdbc:mysql://127.0.0.1/mobileshop"; try{ con=DriverManager.getConnection(uri,"root","J123456"); sql=con.createStatement(); String cdn="SELECT * FROM mobileForm where mobile_version = '"+mobileID+"'"; rs=sql.executeQuery(cdn); out.print("<table border=2>"); out.print("<tr>"); out.print("<th>产品号"); out.print("<th>名称"); out.print("<th>制造商"); out.print("<th>价格"); out.print("<th><font color=blue>放入购物车</font>"); out.print("</TR>"); String picture="welcome.jpg"; String detailMess=""; while(rs.next()){ String number=rs.getString(1); String name=rs.getString(2); String maker=rs.getString(3); String price=rs.getString(4); detailMess=rs.getString(5); picture=rs.getString(6); String goods = "("+number+","+name+","+maker+ ","+price+")#"+price;//便于购物车计算价格,尾缀上"#价格值" goods = goods.replaceAll("\\p{Blank}",""); String button="<form action='putGoodsServlet' method = 'post'>"+ "<input type ='hidden' name='java' value= "+goods+">"+ "<input type ='submit' value='放入购物车' ></form>"; out.print("<tr>"); out.print("<td>"+number+"</td>"); out.print("<td>"+name+"</td>"); out.print("<td>"+maker+"</td>"); out.print("<td>"+price+"</td>"); out.print("<td>"+button+"</td>"); out.print("</tr>"); } out.print("</table>"); out.print("产品详情:<br>"); out.println("<div align=center>"+detailMess+"<div>"); String pic ="<img src='image/"+picture+"' width=260 height=200 ></img>"; out.print(pic); //产片图片 con.close(); } catch(SQLException exp){} %>(四)查询手机
searchMobile.jsp <div align="center"> <br>查询时可以输入手机的版本号或手机名称及价格。<br> 手机名称支持模糊查询。 <br>输入价格是在2个值之间的价格,格式是:价格1-价格2<br> 例如 3987-8976 <FORM action="searchByConditionServlet" Method="post" > <br>输入查询信息:<Input type=text name="searchMess"><br> <Input type =radio name="radio" value="mobile_version">手机版本号 <Input type =radio name="radio" value="mobile_name" checked="ok">手机名称 <Input type =radio name="radio" value="mobile_price">手机价格 <br><Input type=submit name="g" value="提交"> </Form> </div> SearchByCondition.java public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ request.setCharacterEncoding("gb2312"); String searchMess= request.getParameter("searchMess"); String radioMess= request.getParameter("radio"); if(searchMess==null||searchMess.length()==0) { fail(request,response,"没有查询信息,无法查询"); return; } String condition=""; if(radioMess.equals("mobile_version")) { condition = "SELECT * FROM mobileForm where mobile_version ='"+searchMess+"'"; } else if(radioMess.equals("mobile_name")) { condition = "SELECT * FROM mobileForm where mobile_name LIKE '%"+searchMess+"%'"; } else if(radioMess.equals("mobile_price")) { double max=0,min=0; String regex = "[^0123456789.]"; String [] priceMess =searchMess.split(regex); if(priceMess.length==1) { max =min = Double.parseDouble(priceMess[0]); } else if(priceMess.length==2) { min = Double.parseDouble(priceMess[0]); max = Double.parseDouble(priceMess[1]); if(max<min) { double t = max; max = min; min = t; } } else { fail(request,response,"输入的价格格式有错误"); return; } condition = "SELECT * FROM mobileForm where "+ "mobile_price <= "+max+" AND mobile_price>="+min ; } HttpSession session=request.getSession(true); Connection con=null; DataByPage dataBean=null; try{ dataBean=(DataByPage)session.getAttribute("dataBean"); if(dataBean==null){ dataBean=new DataByPage(); //创建Javabean对象 session.setAttribute("dataBean",dataBean); } } catch(Exception exp){ dataBean=new DataByPage(); session.setAttribute("dataBean",dataBean); } String uri = "jdbc:mysql://127.0.0.1/mobileshop?"+ "user=root&password=J123456&characterEncoding=gb2312"; try{ con=DriverManager.getConnection(uri); Statement sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs=sql.executeQuery(condition); rowSet=new CachedRowSetImpl(); //创建行集对象 rowSet.populate(rs); dataBean.setRowSet(rowSet); //行集数据存储在dataBean中 con.close(); //关闭连接 } catch(SQLException exp){} response.sendRedirect("byPageShow.jsp");//重定向到byPageShow.jsp }
(五)查看购物车(要先登录)
<% if(loginBean==null){ response.sendRedirect("login.jsp");//重定向到登录页面 } else { boolean b =loginBean.getLogname()==null|| loginBean.getLogname().length()==0; if(b) response.sendRedirect("login.jsp");//重定向到登录页面 } LinkedList car =loginBean.getCar(); if(car==null) out.print("<h2> 购物车没有物品.</h2>"); else { Iterator<String> iterator=car.iterator(); StringBuffer buyGoods = new StringBuffer(); int n=0; double priceSum =0; out.print("购物车中的物品:<table border=2>"); while(iterator.hasNext()) { String goods=iterator.next(); String showGoods=""; n++; //购车车物品的后缀是“#价格数字",比如“iPhone手机价格3989 #3989” int index=goods.lastIndexOf("#"); if(index!=-1){ priceSum+=Double.parseDouble(goods.substring(index+1)); showGoods = goods.substring(0,index); } buyGoods.append(n+":"+showGoods); String del="<form action='deleteServlet' method = 'post'>"+ "<input type ='hidden' name='delete' value= "+goods+">"+ "<input type ='submit' value='删除' ></form>"; out.print("<tr><td>"+showGoods+"</td>"); out.print("<td>"+del+"</td></tr>"); } out.print("</table>"); String orderForm = "<form action='buyServlet' method='post'>"+ " <input type ='hidden' name='buy' value= "+buyGoods+" >"+ " <input type ='hidden' name='price' value= "+priceSum+" >"+ "<input type ='submit' value='生成订单'></form>"; out.print(orderForm); }
(六)查看订单(要先登录)
<% if(loginBean==null){ response.sendRedirect("login.jsp");//重定向到登录页面 } else { boolean b =loginBean.getLogname()==null|| loginBean.getLogname().length()==0; if(b) response.sendRedirect("login.jsp");//重定向到登录页面 } Connection con; Statement sql; ResultSet rs; try{ Class.forName("com.mysql.jdbc.Driver"); } catch(Exception e){} try { String uri= "jdbc:mysql://127.0.0.1/mobileshop"; String user="root"; String password="J123456"; con=DriverManager.getConnection(uri,user,password); sql=con.createStatement(); String cdn= "SELECT id,mess,sum FROM orderform where logname= '"+loginBean.getLogname()+"'"; rs=sql.executeQuery(cdn); out.print("<table border=2>"); out.print("<tr>"); out.print("<th width=100>"+"订单号"); out.print("<th width=100>"+"信息"); out.print("<th width=100>"+"价格"); out.print("</TR>"); while(rs.next()){ out.print("<tr>"); out.print("<td >"+rs.getString(1)+"</td>"); out.print("<td >"+rs.getString(2)+"</td>"); out.print("<td >"+rs.getString(3)+"</td>"); out.print("</tr>") ; } out.print("</table>"); con.close(); } catch(SQLException e){ out.print(e); } %>(七)退出
package myservlet.control; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HandleExit extends HttpServlet { public void init(ServletConfig config) throws ServletException{ super.init(config); } public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException { HttpSession session=request.getSession(true); session.invalidate(); //销毁用户的session对象 response.sendRedirect("index.jsp"); //返回主页 } public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException { doPost(request,response); } }页面分为三个部分,最上面是标题部分,最左边是用dtree做的树形菜单,右边是显示内容
产品信息管理、订单信息管理还没实现,但关键代码与前面两部分的差不多
tag都是参考书本第六章的例子
(一)页面
index.html <title>欢迎光临“智多星”智能手机销售网</title> </head> <frameset rows="8%,90%,*"> <frame src="top.html"> <frameset cols="20%,*"> <frame src="left.html"> <frame src="main.html" name="main"> </frameset> <frame src="cpright.html"> </frameset> left.html <head> <meta charset="UTF-8"> <title>菜单</title> <link rel="StyleSheet" href="dtree.css" type="text/css" /> <script type="text/javascript" src="dtree.js"></script> </head> <body bgcolor=#FFFCEC> <div class="dtree"> <a href="javascript: d.openAll();">展开所有</a> | <a href="javascript: d.closeAll();">关闭所有</a> <script type="text/javascript"> d = new dTree('d'); d.add(0,-1,'功能模块'); d.add(1,0,'用户信息管理',''); d.add(2,1,'查询用户信息','query1.jsp','','main'); d.add(3,1,'删除用户信息','delete1.jsp','','main'); d.add(4,1,'修改用户信息','modify1.jsp','','main'); d.add(5,0,'产品分类管理',''); d.add(6,5,'查询产品分类','query2.jsp','','main'); d.add(7,5,'删除产品分类','delete2.jsp','','main'); d.add(8,5,'修改产品分类','modify2.jsp','','main'); d.add(9,0,'产品信息管理',''); d.add(10,9,'查询产品信息','query3.jsp','','main'); d.add(11,9,'删除产品信息','delete3.jsp','','main'); d.add(12,9,'修改产品信息','modify3.jsp','','main'); d.add(13,0,'订单信息管理',''); d.add(14,13,'查询订单信息','query4.jsp','','main'); document.write(d);
(二)用户信息管理
查询用户信息
query1.jsp <FORM action="" Method="post" > <br>输入要查询信息的用户名:<Input type=text name="userlog"> <Input type=submit name="g" value="提交"> </Form> <% String userlog=request.getParameter("userlog"); if(userlog==null) userlog=""; %> 查询结果如下: <mobile:Queryuser userlog="<%=userlog%>" /> <BR> <%=Result%> Queryuser.tag <%@ tag pageEncoding="GB2312" %> <%@ tag import="java.sql.*" %> <%@ attribute name="userlog" required="true" %> <%@ variable name-given="Result" scope="AT_END" %> <% StringBuffer result; result=new StringBuffer(); try{ Class.forName("com.mysql.jdbc.Driver"); } catch(Exception e){} Connection con; Statement sql; ResultSet rs; int n=0; try{ String uri="jdbc:mysql://127.0.0.1/mobileshop?"+ "user=root&password=J123456&characterEncoding=gb2312"; con=DriverManager.getConnection(uri); DatabaseMetaData metadata=con.getMetaData(); ResultSet rs1=metadata.getColumns(null,null,"user",null); sql=con.createStatement(); String condition= "SELECT * FROM user Where logname ='"+userlog+"'"; rs=sql.executeQuery(condition); out.print("<table border=1>"); out.print("<tr>"); out.print("<th width=50>"+"用户名"); out.print("<th width=50>"+"电话"); out.print("<th width=100>"+"地址"); out.print("<th width=100>"+"真实姓名"); out.print("</TR>"); while(rs.next()){ out.print("<tr>"); out.print("<td >"+rs.getString(1)+"</td>"); out.print("<td >"+rs.getString(3)+"</td>"); out.print("<td >"+rs.getString(4)+"</td>"); out.print("<td >"+rs.getString(5)+"</td>"); out.print("</tr>") ; } out.print("</table>"); con.close(); } catch(SQLException e){ result.append(e); } jspContext.setAttribute("Result",new String(result)); %>删除用户信息
delete1.jsp <FORM action="delete11.jsp" method=post> <BR>输入要删除的记录的用户: <Input type="text" name="userlog" size=8> <Input type="submit" name="b" value="提交"> </FORM> <BR>用户表删除记录前的记录是: <mobile:queryalluser /> <BR> <%=Result %> delete11.jsp <% String userlog=request.getParameter("userlog"); if(userlog==null) userlog=""; %> <mobile:Deluser userlog="<%=userlog%>" /> <BR>用户表删除记录后的记录是: <mobile:queryalluser /> <BR> <%=Result %> Deluser.tag <% String condition = "DELETE FROM user WHERE logname = '"+userlog+"'"; try{ Class.forName("com.mysql.jdbc.Driver"); } catch(Exception e){} Connection con; Statement sql; ResultSet rs; try{ String uri= "jdbc:mysql://127.0.0.1/mobileshop?"+ "user=root&password=J123456&characterEncoding=gb2312"; con=DriverManager.getConnection(uri); sql=con.createStatement(); sql.executeUpdate(condition); con.close(); } catch(Exception e){ out.print(""+e); } %>修改用户信息
modify1.jsp <FORM action="modify11.jsp" Method="post" > <table border=1> <tr><td>输入要修改信息的用户名:</td> <td><Input type=text name="userlog"></td></tr> <tr><td>输入新的电话:</td> <td><Input type=text name="newtel"></td></tr> <tr><td>输入新的地址:</td> <td><Input type=text name="newaddr"></td></tr> <tr><td>输入新的真实姓名:</td> <<td><Input type=text name="newname"></td></tr> </table> <BR> <Input type=submit name="g" value="提交"> </Form> 用户表修改前信息如下: <mobile:queryalluser /> <BR> <%=Result%> modify11.jsp <% String userlog=request.getParameter("userlog"); String newtel=request.getParameter("newtel"); String newaddr=request.getParameter("newaddr"); String newname=request.getParameter("newname"); %> <mobile:modifyuser userlog="<%=userlog%>" newtel="<%=newtel%>" newaddr="<%=newaddr%>" newname="<%=newname%>"/> <BR>用户表修改信息后的记录是: <mobile:queryalluser /> <BR> <%=Result %> </div> mofidyuser.tag <%@ attribute name="userlog" required="true" %> <%@ attribute name="newtel" required="true" %> <%@ attribute name="newaddr" required="true" %> <%@ attribute name="newname" required="true" %> <% String condition1="UPDATE user SET realname= '"+newname+ "' WHERE logname="+"'"+userlog+"'" , condition2="UPDATE user SET phone= '"+newtel+ "' WHERE logname="+"'"+userlog+"'", condition3="UPDATE user SET address= "+newaddr+ " WHERE logname="+"'"+userlog+"'" ; try{ Class.forName("com.mysql.jdbc.Driver"); } catch(Exception e){} Connection con; Statement sql; ResultSet rs; try{ String uri= "jdbc:mysql://127.0.0.1/mobileshop?"+ "user=root&password=J123456&characterEncoding=gb2312"; con=DriverManager.getConnection(uri); sql=con.createStatement(); sql.executeUpdate(condition1); sql.executeUpdate(condition2); sql.executeUpdate(condition3); con.close(); } catch(Exception e){ out.print(""+e); } %> queryalluser.tag <%@ variable name-given="Result" scope="AT_END" %> <% StringBuffer result; result=new StringBuffer(); try{ Class.forName("com.mysql.jdbc.Driver"); } catch(Exception e){} Connection con; Statement sql; ResultSet rs; int n=0; try{ String uri="jdbc:mysql://127.0.0.1/mobileshop?"+ "user=root&password=J123456&characterEncoding=gb2312"; con=DriverManager.getConnection(uri); DatabaseMetaData metadata=con.getMetaData(); ResultSet rs1=metadata.getColumns(null,null,"user",null); sql=con.createStatement(); String condition= "SELECT * FROM user"; rs=sql.executeQuery(condition); out.print("<table border=1>"); out.print("<tr>"); out.print("<th width=50>"+"用户名"); out.print("<th width=50>"+"电话"); out.print("<th width=100>"+"地址"); out.print("<th width=100>"+"真实姓名"); out.print("</TR>"); while(rs.next()){ out.print("<tr>"); out.print("<td >"+rs.getString(1)+"</td>"); out.print("<td >"+rs.getString(3)+"</td>"); out.print("<td >"+rs.getString(4)+"</td>"); out.print("<td >"+rs.getString(5)+"</td>"); out.print("</tr>") ; } out.print("</table>"); con.close(); } catch(SQLException e){ result.append(e); }(三)产品分类管理
代码与用户信息管理的差不多,这里就不再放出关键代码
查看产品分类
删除产品分类
修改产品分类
queryall.tag <%@ tag pageEncoding="GB2312" %> <%@ tag import="java.sql.*" %> <%@ attribute name="tableName" required="true" %> <%@ variable name-given="Result" scope="AT_END" %> <% StringBuffer result; result=new StringBuffer(); try{ Class.forName("com.mysql.jdbc.Driver"); } catch(Exception e){} Connection con; Statement sql; ResultSet rs; try{ result.append("<table border=1>"); String uri="jdbc:mysql://127.0.0.1/mobileshop?"+ "user=root&password=J123456&characterEncoding=gb2312"; con=DriverManager.getConnection(uri); DatabaseMetaData metadata=con.getMetaData(); ResultSet rs1=metadata.getColumns(null,null,tableName,null); int 字段个数=0; result.append("<tr>"); while(rs1.next()){ 字段个数++; String clumnName=rs1.getString(4); result.append("<td>"+clumnName+"</td>"); } result.append("</tr>"); sql=con.createStatement(); rs=sql.executeQuery("SELECT * FROM "+tableName); while(rs.next()){ result.append("<tr>"); for(int k=1;k<=字段个数;k++) result.append("<td>"+rs.getString(k)+"</td>"); result.append("</tr>"); } result.append("</table>"); con.close(); } catch(SQLException e){ result.append("请输入正确的用户名和密码"); } jspContext.setAttribute("Result",new String(result)); %>