结对作业(地铁项目)04

changeserchjudge.jsp

<%@ page language="java" import="java.sql.*"  contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>查询</title>
</head>
<body style="text-align:center">
查询结果
<p>
<style>





body {
margin:0px;
background: url(images/2.png) no-repeat;
background-size:100% 100%;
background-attachment:fixed;
}
input {
width: 250px;
height: 44px;
border: none;
/* 元素周围的轮廓无效 */
outline: none;
/* 为元素指定的任何内边距和边框都将在已设定的宽度和高度内进行绘制 */
box-sizing: border-box;
display: block;
padding: 0 16px;
}
.input-text {
margin: 5px auto;
border-radius: 16px;
}

.input-text:hover {
border: 0.5px solid rgb(76, 76, 233);
transition: 0.5s;
border-radius: 4px;
}
</style>
<jsp:useBean id="util" class="User.subway" scope="page" />
<%
String station1=(String)request.getParameter("station1");
String station2=(String)request.getParameter("station2");
if(station1==""||station2==""){
out.print("<script language='javaScript'> alert('输入为空'); window.history.back(-1); </script>");
}
else
{
%>
<table border="1"style="text-align:center;">
<tr>
<td align="center" width=6%>起始站</td>
<td align="center" width=3%>终点站</td>
<td align="center" width=3%>经停站</td>
<td align="center" width=3%>路线</td>

</tr>
<%
int i=0;
Connection connection = util.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {

String sql ="WITH RECURSIVE transfer (start_station, stop_station, stops, path) AS (\n" +
" SELECT station_name, next_station, 1, CAST(CONCAT(line_name,station_name , '->', line_name,next_station) AS CHAR(1000))\n" +
" FROM bj_subway WHERE station_name = ?\n" +
" UNION ALL\n" +
" SELECT p.start_station, e.next_station, stops + 1, CONCAT(p.path, '->', e.line_name, e.next_station)\n" +
" FROM transfer p\n" +
" JOIN bj_subway e\n" +
" ON p.stop_station = e.station_name AND (INSTR(p.path, e.next_station) = 0)\n" +
")\n" +
"SELECT * FROM transfer WHERE stop_station = ?;\n";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1,station1);
preparedStatement.setString(2,station2);
rs = preparedStatement.executeQuery();

while(rs.next())
{
i++;
if (station1.equals(rs.getObject(1))&&station2.equals((rs.getObject(2)))){

%>
<tr>
<td align="center"><%=rs.getObject(1) %></td>
<td align="center"><%=rs.getObject(2) %></td>
<td align="center"><%=rs.getObject(3) %></td>
<td align="center"><%=rs.getObject(4) %></td>

</tr>
<%
}
}
if(i==0)
{
out.print("<script language='javaScript'> alert('没有查询到有关信息'); window.history.back(-1); </script>");
}


} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(rs);
util.close(preparedStatement);
util.close(connection);
}
}
%>
</table>

<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
<br> <input class="input-text" type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br>
</p>
</body>
</html>
posted @   平安喜乐×  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效
点击右上角即可分享
微信分享提示