JSP简单添加,查询功能代码(2)

package test; /*aaaaaaa bbbbbbb ccccccccc*/ /** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author not attributable * @version 1.0 */ public class Jsp1Bean { private String sample = "Start value"; //Access sample property public String getSample() { return sample; } //Access sample property public void setSample(String newValue) { if (newValue!=null) { sample = newValue; } } }

jsp2:

<%@ page contentType="text/html; charset=GB2312" %> <%@ page import="java.sql.*" %> <%@ page language="java" %> <HTML> <HEAD> <TITLE>顺序取得数据</TITLE> </HEAD> <BODY> <CENTER> <FONT SIZE = 5 COLOR = blue>顺序取得数据</FONT> </CENTER> <BR> <HR> <BR> <CENTER> <% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //载入驱动程序类别 Connection con = DriverManager.getConnection("jdbc:odbc:zjyds1"); //建立数据库链接 Statement stmt = con.createStatement(); //建立Statement对象 ResultSet rs; //建立ResultSet(结果集)对象 rs = stmt.executeQuery("SELECT * FROM tab01"); //执行SQL语句 %> <TABLE bgcolor=pink> <TR bgcolor=silver> <TD><B>学 号</B></TD><TD><B>姓 名 </B></TD><TD><B>性 别 </B></TD><TD><B>年 龄 </B></TD><TD><B>地 址</B></TD> </TR> <% //利用while循环将数据表中的记录列出 while (rs.next()) { %> <TR bgcolor=white> <TD><B><%= rs.getString("id") %></B></TD> <TD><B><%= rs.getString("name") %></B></TD> <TD><B><%= rs.getString("sex") %></B></TD> <TD><B><%= rs.getString("age") %></B></TD> <TD><B><%= rs.getString("addr") %></B></TD> </TR> <% } rs.close(); //关闭ResultSet对象 stmt.close(); //关闭Statement对象 con.close(); //关闭Connection对象 %> </TABLE> </CENTER> </BODY> </HTML>

jsp3:

<%@ page contentType="text/html; charset=GB2312" %> <html> <head> <title> jsp3 </title> </head> <jsp:useBean scope="session" /> <jsp:setProperty property="*" /> <body bgcolor="#ffffc0"> <h1> JBuilder Generated JSP </h1> <form method="post"> <br>Enter new value : <input><br> <br><br> <input type="submit" value="Submit"> <input type="reset" value="Reset"> <br> Value of Bean property is :<jsp:getProperty property="sample" /> </form> </body> </html>

jsp4:

<%@ page contentType="text/html; charset=GB2312" %> <html> <head> <title> 登录 </title> </head> <body bgcolor="#ffffc0"> <form method="POST" action="jsp6.jsp"> <p> 用户名:<input type="text" size="20"></p> <p> 密 码:<input type="password" size="20"></p> <p> <input type="radio" value="manage" checked> 管理 <input type="radio" value="statistic">统计</p> <p><input type="submit" value="登 录"> <input type="reset" value="重 写"></p> </form> </body> </html>

jsp6:

<%@ page contentType="text/html; charset=GB2312" %> <html> <head> <title> 接收数据 </title> </head> <body bgcolor="#ffffff"> <% String user,pwd,choice; user=request.getParameter("username"); pwd=request.getParameter("password"); choice=request.getParameter("select"); if(choice.equals("manage")){ //user select manage. %> <jsp:forward page="jsp7.jsp"> <jsp:param value="<%=user%>"/> <jsp:param value="<%=pwd%>"/> </jsp:forward> <% }else{ //user select statistic %> <jsp:forward page="jsp8.jsp"> <jsp:param value="<%=user%>"/> <jsp:param value="<%=pwd%>"/> </jsp:forward> <% } %> </body> </html>

jsp7:

<%@ page contentType="text/html; charset=GB2312" %> <html> <head> <title> jsp7 </title> </head> <body bgcolor="#ffffff"> <h1> 这是管理页 !!! </h1> <br> <% String user,pwd; user=request.getParameter("username"); pwd=request.getParameter("password"); %> username is: <%=user%><br> password is: <%=pwd%><br> </body> </html>

jsp8:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzfwyx.html