地铁查询系统完成的第二阶段 实现了查询的功能1和查询功能2
我与我的同伴完成了这两个基本的查询功能。
查询页面:
chaxun-01.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>地铁信息查询页面</title>
<style type="text/css">
.bg {
background-size:cover;
}
</style>
</head>
<body >
<form action="chaxun-02.jsp" method="get">
<p
style="text-align: center; color: green; font-family: 黑体; font-size: 20px">
地铁线路号:<input type="text" name="lineid"><br>
<input type="submit" value="提交" /> <input type="reset" value="重置" />
</p>
</form>
<form action="chaxun-03.jsp" method="get">
<p
style="text-align: center; color: green; font-family: 黑体; font-size: 20px">
站点查询:<input type="text" name="station"><br>
<input type="submit" value="提交" /> <input type="reset" value="重置" />
</p>
</form>
</body>
</html>
1.实现了输入线路号,输出此地铁线路的所有站
chaxun-02.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<jsp:useBean id="dao" class="DAO.dao"></jsp:useBean>
<jsp:useBean id="dbutil" class="DBUTIL.dbutil"></jsp:useBean>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1> 地铁线路所有站名</h1>
<body>
<body>
<table border="1" align="center">
<tr>
<th>1.地铁线路号</th>
<th>2.地铁站点号</th>
<th>3.地铁站名</th>
</tr>
<%
String lineid=request.getParameter("lineid");
Connection connection = dbutil.getConnection();
PreparedStatement preparedStatement = null;
ResultSet rs = null;
try{
String sql="select * from underground where lineid =?";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1 ,lineid);
rs = preparedStatement.executeQuery();
while(rs.next()){
%>
<tr>
<td><%=rs.getString("lineid") %></td>
<td><%=rs.getString("stationid") %></td>
<td><%=rs.getString("station") %></td>
<%
}
}catch (Exception ex){
ex.printStackTrace();
}
%>
</table>
</body>
</html>
2.实现输入站点名称输出途径该站点所有线路的查询功能。
chaxun-03.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<jsp:useBean id="dao" class="DAO.dao"></jsp:useBean>
<jsp:useBean id="dbutil" class="DBUTIL.dbutil"></jsp:useBean>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1> 站点查询页面</h1>
<body>
<body>
<table border="1" align="center">
<tr>
<th>1.地铁站名</th>
<th>2.线路名称</th>
</tr>
<%
String station=request.getParameter("station");
Connection connection = dbutil.getConnection();
PreparedStatement preparedStatement = null;
ResultSet rs = null;
try{
String sql="select * from underground where station =?";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1 ,station);
rs = preparedStatement.executeQuery();
while(rs.next()){
%>
<tr>
<td><%=rs.getString("station") %></td>
<td><%=rs.getString("lineid") %></td>
<%
}
}catch (Exception ex){
ex.printStackTrace();
}
%>
</table>
</body>
</html>