地铁查询
metroequary.jsp
1 <%@ page import="java.util.ArrayList" %> 2 <%@ page import="com.metro.bean.Stadion" %><%-- 3 Created by IntelliJ IDEA. 4 User: dell 5 Date: 2022/4/1 6 Time: 20:56 7 To change this template use File | Settings | File Templates. 8 --%> 9 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 10 <html> 11 <head> 12 <meta charset="UTF-8"> 13 <title>subwayequary</title> 14 <style> 15 #top{ 16 height:150px; 17 width:100% ; 18 background-color: aqua; 19 border:1px; 20 } 21 #bottom{ 22 height: 600px; 23 width: 100%; 24 background-color: aquamarine; 25 text-align: center; 26 } 27 #left-bottom{ 28 height: 600px; 29 width: 200px; 30 text-align: center; 31 float: left; 32 background-color: aquamarine; 33 } 34 #left-bottom1{ 35 height: 180px; 36 width: 200px; 37 text-align: center; 38 } 39 #left-bottom2{ 40 height: available; 41 width: 200px; 42 text-align: center; 43 } 44 #right-bottom{ 45 height: 600px; 46 width: 1000px; 47 text-align: center; 48 background-color:aqua; 49 float: left; 50 } 51 52 #chaxunkuang{ 53 width: 100%; 54 height: 200px; 55 background-color: aqua; 56 text-align: center; 57 } 58 .equary{ 59 margin-top: 20px; 60 list-style: none; 61 text-align: center; 62 margin-left: 0px; 63 margin-bottom: 10px; 64 } 65 h1{ 66 text-align: center; 67 } 68 #show{ 69 border: 3px; 70 margin-left: 30px; 71 margin-top: 30px; 72 width: available; 73 } 74 75 </style> 76 <script src="jquery-1.7.2.js"></script> 77 <script type="text/javascript"> 78 function station1() { 79 80 document.getElementById("chaxunkuang").innerHTML="<form action=\"http://localhost:8080/metroequary/req?method=station1\" method=\"post\">" 81 + "<table><br><br>" 82 + " <tr>" 83 + " <td>输入要查询的地铁站:</td>" 84 +" <td><input type=\"text\" name=\"station\"></td>" 85 + "</tr>" 86 +"</table>" 87 + "<input type=\"submit\" value=\"提交\">" 88 +"</form>"; 89 document.getElementById("result").innerHTML="" 90 } 91 function xianlu(){ 92 <%flag = 2;%> 93 document.getElementById("chaxunkuang").innerHTML="<form action=\"http://localhost:8080/metroequary/req?method=xianlu\" method=\"post\">" 94 +"<table id='show'><br><br>" 95 +" <tr>" 96 +" <td>请选择地铁线路名" 97 +" <select name=\"lineno\">" 98 +" <option value=\"1\">线路1</option>" 99 +" <option value=\"2\">线路2</option>" 100 +" <option value=\"3\">线路3</option>" 101 +" <option value=\"4\">线路4</option>" 102 +" <option value=\"5\">线路5</option>" 103 +" <option value=\"6\">线路6</option>" 104 +" <option value=\"7\">线路7</option>" 105 +" <option value=\"8\">线路8</option>" 106 +" <option value=\"9\">线路9</option>" 107 +" <option value=\"10\">线路10</option>" 108 +" <option value=\"11\">线路11</option>" 109 +" <option value=\"12\">线路12</option>" 110 + "</select>" 111 +" </td>" 112 +" </tr>" 113 +"</table>" 114 +"<input type=\"submit\" value=\"提交\">" 115 +"</form>" 116 document.getElementById("result").innerHTML=""; 117 118 } 119 function qizhong() { 120 <%flag = 3;%> 121 document.getElementById("chaxunkuang").innerHTML="<form action=\"http://localhost:8080/metroequary/req?method=qizhong\" method=\"post\" >" 122 +"<table id=\"show\"><br><br>" 123 + " <tr>" 124 + " <td>请输入起始站点</td>" 125 + " <td><input type=\"text\" name=\"start\"></td>" 126 + " <td>请输入终点</td>" 127 + " <td><input type=\"text\" name=\"end\"></td>" 128 + " </tr>" 129 + "</table>" 130 +"<input type=\"submit\" value=\"提交\">" 131 +"</form>" 132 133 } 134 </script> 135 </head> 136 <body> 137 <div id="top" > 138 <h1>地铁查询</h1> 139 </div> 140 <hr> 141 <div id="bottom"> 142 <div id="left-bottom"> 143 <div id="left-bottom1"> 144 <ul> 145 <li class="equary"><button id="station" onclick="station1()">站点查询</button></li> 146 <li class="equary"><button id="line" onclick="xianlu()">线路查询</button></li> 147 <li class="equary"><button id="route" onclick="qizhong()">起点终点查询</button></li> 148 </ul> 149 </div> 150 <hr> 151 <div id="left-bottom2"> 152 <p>查询结果显示</p> 153 </div> 154 </div> 155 <div id="right-bottom"> 156 <div id="right-bottom1"> 157 <div id="chaxunkuang"> 158 159 </div> 160 </div> 161 <hr> 162 <div id="right-bottom2"> 163 <% String[] lineno = (String[]) request.getAttribute("xianlu"); 164 ArrayList<Stadion> linesStation = (ArrayList<Stadion>) request.getAttribute("lineStation"); 165 request.setCharacterEncoding("utf-8"); 166 int flag = 0; 167 %> 168 <div id="result"> 169 <% if(flag == 1){%> 170 <%for(String s:lineno){ 171 if(s!=null) 172 %> 173 <%="线路号:"+s%> 174 <br> 175 <%}%> 176 <%}else if(flag == 2){%> 177 <% for(Stadion stadion: linesStation) {%> 178 <%=stadion.getStaName()+"->"%> 179 <%}%> 180 <%}%> 181 182 </div> 183 </div> 184 </div> 185 </div> 186 </body> 187 </html>
LineDAO.java
1 package dao; 2 3 import java.sql.Connection; 4 import java.sql.PreparedStatement; 5 import java.sql.ResultSet; 6 import java.sql.SQLException; 7 import java.time.Year; 8 9 public class LineDAO { 10 public String checkallstation(String linename) throws SQLException, ClassNotFoundException { 11 String sql = "select * from linelist where linename = ?"; 12 Connection connection = DBUtil.getConnection(); 13 if(connection!=null){ 14 System.out.println("连接数据库成功!!!"); 15 } 16 System.out.println(linename); 17 PreparedStatement preparedStatement = connection.prepareStatement(sql); 18 preparedStatement.setString(1,linename); 19 ResultSet rs = preparedStatement.executeQuery(); 20 String station = "天河 体育馆 广州东站"; 21 System.out.println("222"); 22 if (rs.next()) { 23 System.out.println("333"); 24 station = rs.getString("allstation"); 25 } 26 // if(!rs.next()){ 27 // System.out.println("无查询结果"); 28 // } 29 30 return station; 31 } 32 }
StationDAO.java
1 package dao; 2 3 import entity.station; 4 5 import java.sql.Connection; 6 import java.sql.PreparedStatement; 7 import java.sql.ResultSet; 8 import java.sql.SQLException; 9 10 public class StationDAO { 11 public boolean isonsameline(station a, station b){ 12 if(a.getOnline().equals(b.getOnline())) 13 return true; 14 return false; 15 } 16 17 public station checkstation(String str) throws SQLException, ClassNotFoundException { 18 String sql = "select * from stationlist where Sname = ?"; 19 Connection connection = DBUtil.getConnection(); 20 if(connection!=null){ 21 System.out.println("连接数据库成功!!!"); 22 } 23 System.out.println(str); 24 PreparedStatement preparedStatement = connection.prepareStatement(sql); 25 preparedStatement.setString(1,str); 26 ResultSet rs = preparedStatement.executeQuery(); 27 String sname = "天河 体育馆 广州东站"; 28 int sid =-1; 29 String online = null; 30 if (rs.next()) { 31 sname = rs.getString("Sname"); 32 online = rs.getString("online"); 33 sid = rs.getInt("Sid"); 34 } 35 station st = new station(sname,online,sid); 36 // if(!rs.next()){ 37 // System.out.println("无查询结果"); 38 // } 39 40 return st; 41 } 42 }
Station.java
1 package entity; 2 3 public class station { 4 public String station; 5 public String online; 6 public int id; 7 8 public int getId() { 9 return id; 10 } 11 12 public void setId(int id) { 13 this.id = id; 14 } 15 16 public String getStation() { 17 return station; 18 } 19 20 public station(String station, String online, int id) { 21 this.station = station; 22 this.online = online; 23 this.id = id; 24 } 25 26 public void setStation(String station) { 27 this.station = station; 28 } 29 30 public String getOnline() { 31 return online; 32 } 33 34 public void setOnline(String online) { 35 this.online = online; 36 } 37 }
Line.java
1 package entity; 2 3 public class line { 4 public String linename; 5 public String allstation; 6 7 public line(String linename, String allstation) { 8 this.linename = linename; 9 this.allstation = allstation; 10 } 11 12 public String getLinename() { 13 return linename; 14 } 15 16 public void setLinename(String linename) { 17 this.linename = linename; 18 } 19 20 public String getAllstation() { 21 return allstation; 22 } 23 24 public void setAllstation(String allstation) { 25 this.allstation = allstation; 26 } 27 28 29 }
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号