组队-地铁查询

完成了页面的jsp文件,下面展示部分代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="jakarta.servlet.http.HttpSession" %>
<%@page import="jakarta.servlet.http.HttpServletResponse" %>
<%@page import="jakarta.servlet.http.HttpServletRequest" %>
<%@page import="com.Bean.*" %>
<%@page import="java.util.List" %>
<%@page import="java.util.ArrayList" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>

<style type="text/css">

div{
background-color:#3F51B5;
width:300px;
height:500px;
border-radius:5px;
}

div p{
font-family:YouYuan;
font-size:20px;
color:#E8EAF6;
}

div p input{
height:20px;
border-radius:3px;
border:0px;
}

#check{
width:70px;
height:25px;
border-radius:3px;
color:white;
background-color:#004D99;
text-align:center;
text-decoration:none;
border:none;
position:relative;
left:110px;
}

#check:hover{
background-color:#6699CC;
}

#information{
width:260px;
height:300px;
border-radius:3px;
display:block;
margin:0 auto;
font-family:YouYuan;
font-size:13px;
}

</style>

</head>
<body>

<div>
<form action="shortest.jsp" method="post" onsubmit="return oncheck()">
<br/>
<p>  起始站:
<input type="text" name="start" id="start" placeholder=" Starting station">
</p>
<p>  终点站:
<input type="text" name="end" id="end" placeholder=" Ending station">
</p>
<p><input type="submit" value="查询" name="check" id="check"></p>
<textarea name="information" id="information" readonly="readonly">
线路信息:
</textarea>
</form>
</div>

<script type="text/javascript">


function oncheck() {

var start = document.getElementById("start");
var end = document.getElementById("end");
var strstart = start.value;
var strend = end.value;

if(strstart == '') {
alert('起始站为空');
start.focus();
return false;
}
if(strend == '') {
alert('终点站为空');
end.focus();
return false;
}

return true;
}

</script>
</body>
</html>

 

 


<%@ page import="java.sql.*" contentType="text/html;charset=UTF-8" language="java" %>


<%@ page import="java.util.List"%>
<%@ page import="java.util.ArrayList"%>

<%@ page import="com.DBUtil.SubwayDBUtil" %>

<html>
<head>
<title>从zhandian.jsp获取数据</title>

</head>
<body>

<%
//获取前端数据
request.setCharacterEncoding("UTF-8");//编码一定设置
List<String> s = new ArrayList<>();//用于保存线路
String s1;

String stopName=request.getParameter("start");


PreparedStatement ps = null;
Connection con = null;
ResultSet rs = null;

try {

con = SubwayDBUtil.getConn();
String sql = "select * from bj_subway where sname =?";
ps = con.prepareStatement(sql);
ps.setString(1, stopName);
rs = ps.executeQuery();
%>
<table border="1"style="text-align:center;">
<tr>
<td align="center" width=8%>线路号</td>
<%

while(rs.next())

{
%>
</tr>
<tr>
<td align="center"><%=rs.getObject(2) %></td>
</tr>
<%
}

}catch (SQLException e) {
e.printStackTrace();
}catch (Exception e) {

e.printStackTrace();

}finally {

try {
if(rs!= null) rs.close();
if(ps!= null) ps.close();
if(con!= null) con.close();

} catch (SQLException e) {
e.printStackTrace();
}

}



%>


</body>
</html>

 


<%@ page import="java.sql.*" contentType="text/html;charset=UTF-8" language="java" %>


<%@ page import="java.util.List"%>
<%@ page import="java.util.ArrayList"%>

<%@ page import="com.DBUtil.SubwayDBUtil" %>
<jsp:useBean id="util" class="com.Dao.Subway" scope="page" />
<html>
<head>
<title>从xianlu.jsp获取数据</title>

</head>
<body>

<%
request.setCharacterEncoding("UTF-8");//编码一定设置
String start=request.getParameter("start");
String end=request.getParameter("end");
List<String> paths = new ArrayList<>();
paths=util.shortPace(start,end);

%>
<table border="1"style="text-align:center;">
<tr>
<td align="center" width=3%>经历站名个数</td>
<td align="center" width=30%>最短路径</td>
</tr>

<tr>
<td align="center"><%=paths.get(1) %></td>
<td align="center"><%=paths.get(0) %></td>
</tr>

 


</body>
</html>

 

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="jakarta.servlet.http.HttpSession" %>
<%@page import="jakarta.servlet.http.HttpServletResponse" %>
<%@page import="jakarta.servlet.http.HttpServletRequest" %>
<%@page import="com.Bean.*" %>
<%@page import="java.util.List" %>
<%@page import="java.util.ArrayList" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>

<style type="text/css">

div{
background-color:#3F51B5;
width:300px;
height:500px;
border-radius:5px;
}

div p{
font-family:YouYuan;
font-size:20px;
color:#E8EAF6;
}

div p input{
height:20px;
border-radius:3px;
border:0px;
}

#check{
width:70px;
height:25px;
border-radius:3px;
color:white;
background-color:#004D99;
text-align:center;
text-decoration:none;
border:none;
position:relative;
left:110px;
}

#check:hover{
background-color:#6699CC;
}

#information{
width:260px;
height:300px;
border-radius:3px;
display:block;
margin:0 auto;
font-family:YouYuan;
font-size:13px;
}

</style>

</head>
<body>

<div>
<form action="showzhandian.jsp" method="post" onsubmit="return oncheck()">
<br/>
<p>  站点:
<input type="text" name="start" id="start" placeholder=" Starting station">
</p>

<p><input type="submit" value="查询" name="check" id="check"></p>

<textarea name="information" id="information" readonly="readonly">
该站点所属路线:
</textarea>
</form>
</div>

<script type="text/javascript">

function oncheck() {

var start = document.getElementById("start");

var strstart = start.value;


if(strstart == '') {
alert('站点为空');
start.focus();
return false;
}
return true;
}

</script>
</body>
</html>

posted @ 2023-03-20 21:51  Weebles  阅读(12)  评论(0编辑  收藏  举报