<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%String no=request.getParameter("oo"); %>
<% Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/myschool1";
String user="root";
String password="123456";
Connection c1=DriverManager.getConnection(url,user,password);
Statement s1 = c1.createStatement();
ResultSet r1=s1.executeQuery("select * from student where studentno='"+no+"'");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.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 border="1">
<tr>
<td>学号</td>
<td>姓名</td>
</tr>
<% while (r1.next()){%>
<tr>
<td><%=r1.getString("studentno")%></td>
<td><%=r1.getString("studentname")%></td>
</tr>
<% } %>
</table>
</body>
</html>
<% r1.close();
s1.close();
c1.close();%>
MyJsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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 'MyJsp.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>
<form action="index.jsp"><table>
<th colspan="2"> 条件查询</th>
<tr>
<td>学号</td>
<td><input type="text" name="oo" ></td></tr>
<tr ><td>
<input type="submit" value="搜索" ></td> </tr>
</table></form>
</body>
</html>
代码来源:何茜老师