将一个jsp页面上表单的数据提交到当前的这个页面。在根据在表单的内容查询数据库,显示数据库内容!
<%@pagecontentType="text/html;charset=gb2312"%><%@pagelanguage="java"import="java.sql...
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page language="java" import="java.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>会员管理</title>
</head>
<body>
<form action="" method="post">
<div align="center">学号:
<input name="num" type="text" id="num">
<input type="button" value="go">
</div>
</form>
<%
//变量声明
String num="";
num=(String)request.getAttribute("num");
java.sql.Connection sqlCon; //数据库连接对象
java.sql.Statement sqlStmt; //SQL语句对象
java.sql.ResultSet sqlRst; //结果集对象
java.lang.String strCon; //数据库连接字符串
java.lang.String strSQL; //SQL语句
//装载JDBC驱动程序
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
strCon = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=stu";
sqlCon = java.sql.DriverManager.getConnection(strCon,"jzf","123");
sqlStmt = sqlCon.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);//准备SQL语句
strSQL = "select * from score1";
String sql="select * from score1 where num='num'";
if(num==null)
sqlRst = sqlStmt.executeQuery(strSQL);
else
sqlRst = sqlStmt.executeQuery(sql);
while(sqlRst.next())
{String t1=sqlRst.getString(1);
String t2=sqlRst.getString(2);
String t3=sqlRst.getString(3);
%>
<table width="300" border="1" align="center">
<tr>
<td width="100"><%=t1%></td>
<td width="100"><%=t2%></td>
<td width="100"><%=t3%></td>
<td width="100"><%=num%></td>
</tr>
</table>
<%
}
sqlRst.close();
//关闭SQL语句对象
sqlStmt.close();
//关闭数据库
sqlCon.close();
%>
</body>
</html> 展开
<%@ page language="java" import="java.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>会员管理</title>
</head>
<body>
<form action="" method="post">
<div align="center">学号:
<input name="num" type="text" id="num">
<input type="button" value="go">
</div>
</form>
<%
//变量声明
String num="";
num=(String)request.getAttribute("num");
java.sql.Connection sqlCon; //数据库连接对象
java.sql.Statement sqlStmt; //SQL语句对象
java.sql.ResultSet sqlRst; //结果集对象
java.lang.String strCon; //数据库连接字符串
java.lang.String strSQL; //SQL语句
//装载JDBC驱动程序
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
strCon = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=stu";
sqlCon = java.sql.DriverManager.getConnection(strCon,"jzf","123");
sqlStmt = sqlCon.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);//准备SQL语句
strSQL = "select * from score1";
String sql="select * from score1 where num='num'";
if(num==null)
sqlRst = sqlStmt.executeQuery(strSQL);
else
sqlRst = sqlStmt.executeQuery(sql);
while(sqlRst.next())
{String t1=sqlRst.getString(1);
String t2=sqlRst.getString(2);
String t3=sqlRst.getString(3);
%>
<table width="300" border="1" align="center">
<tr>
<td width="100"><%=t1%></td>
<td width="100"><%=t2%></td>
<td width="100"><%=t3%></td>
<td width="100"><%=num%></td>
</tr>
</table>
<%
}
sqlRst.close();
//关闭SQL语句对象
sqlStmt.close();
//关闭数据库
sqlCon.close();
%>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询