日期:2014-05-17 浏览次数:20799 次
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=GBK"%> <jsp:useBean id="queryBean" scope="page" class="ch4.QueryBean"/> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'MySql.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <table width="60%" border="1"> <tr><td width="50%">姓名</td> <td width="25%">学号</td> <td width="25%">学分</td> </tr> <%ResultSet rs=queryBean.getQuery("select * from ta"); while(rs.next()){ %> <tr><td width="50%"><%=rs.getString(1)%></td> <td width="25%"><%=rs.getInt(2) %></td> <td width="25%"><%=rs.getInt(3) %></td></tr> <% } rs.close();%> </table> <form action="" method="post"> 姓名 <input type="text" name="name" id="name"><BR> 学号 <input type="text" name="num" id="num" ><br> 学分 <input type="text" name="point" id="point" ><input type="reset" value="清除" > <input type="submit" value="add" name="add"> <input type="submit" value="modify" name="modify"> <jsp:setProperty property="submit" name="queryBean" value="<%=request.getParameter(\"submit\") %>"/> <jsp:setProperty property="str1" name="queryBean" value="<%= request.getParameter(\"name\")%>"/> <jsp:setProperty property="str2" name="queryBean" value="<%= request.getParameter(\"num\")%>"/> <jsp:setProperty property="str3" name="queryBean" value="<%=request.getParameter(\"point\")%>"/> <% try{ String str1=request.getParameter("name"); int str2=Integer.parseInt(request.getParameter("num")); int str3=Integer.parseInt(request.getParameter("point")); //queryBean.setModify("insert into ta values ('"+str1+"',"+str2+","+str3+");");使用这个方法可以存入值 queryBean.add(); out.println(str1); } catch (NumberFormatException e){ out.println("请输入数字");} %> </form> </body> </html>
package ch4; imp