-
Notifications
You must be signed in to change notification settings - Fork 1
/
SearchTrain.jsp
439 lines (366 loc) · 11.7 KB
/
SearchTrain.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Trains</title>
<meta name="keywords" content="Home" />
<link href="./css/templatemo_style.css" rel="stylesheet" type="text/css" />
<link href="css/jquery.ennui.contentslider.css" rel="stylesheet" type="text/css" media="screen,projection" />
<%!
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
public void jspInit(){
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/train","root","");
}
catch(Exception e ){
e.printStackTrace();
}
}
%>
<script type="text/javascript">
function change(){
var sid= document.getElementById("select1").value;
var cid=document.getElementById("select1").selectedIndex;
var val = document.getElementById("select1").options[cid].text;
var url = window.location.href;
var urlindex = url.indexOf('?');
var url1 = "";
if(urlindex > -1){
url1 = url.substring(0, urlindex);
window.location.replace(url1+"?sid="+sid+"&value="+val);
}
else{
window.location.replace(url+"?sid="+sid+"&value="+val);
}
}
function extract(){
var sid= document.getElementById("select1").value;
var did= document.getElementById("select2").value;
var id1=document.getElementById("select2").selectedIndex;
var val1 = document.getElementById("select2").options[id1].text;
var url = window.location.href;
var urlindex = url.indexOf('?');
var url1 = "";
if(urlindex > -1){
url1 = url.substring(0, urlindex);
window.location.replace(url1+"?src="+sid+"&did="+did+"&des="+val1);
}
else{
window.location.replace(url+"?src="+sid+"&did="+did+"&des="+val1);
}
}
</script>
<!-- Special Font & Symbol -->
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script>
$(function(){
$("#header").load("header.html");
});
</script>
<script>
$(function(){
$("#footer").load("footer.html");
});
</script>
</head>
<body>
<div id="templatemo_wrapper">
<div id="templatemo_header">
<div id="site_title">
<h1><a href="home.jsp">
<img src="./images/logo.jpg" alt="Commuters Guide" width="480" height="93" />
</a></h1>
</div>
<!-- end of templatemo_menu -->
<div class="cleaner"></div>
</div> <!-- end of header -->
<div id="header"></div>
<div id="templatemo_content">
<!-- Form Body -->
<div align="center">
<form name="form1">
<h1> Search Trains Between Stations </h1>
<table>
<tr>
<td> Source Station </td>
<td>
<%
String value = request.getParameter("value");
String sql1="select * from route_main";
pstmt = con.prepareStatement(sql1);
rs = pstmt.executeQuery();
%>
<select id="select1" name="source" onchange="change();" onfocus="back()">
<option value="0">--Please Select--</option>
<% while(rs.next()){ %>
<% if(rs.getString(3).equals(value)){%>
<option value="<%= value%>" selected="selected" disabled="disabled"><%=value%></option>
<%
}
else{
%>
<option value="<%=rs.getString(2)%>"><%=rs.getString(3)%></option>
<%
}
}
%>
</select>
<!-- JavaScript To Eliminate Similar Station Names Generated From BackEnd -->
<script type="text/javascript">
function back(){
var sel = document.form1.source;
try{
//alert("Start back()" + sel.length);
for (var i=0; i< sel.length - 1; i++)
{
//alert(sel.options[i].text);
for (var j=i+1; j< sel.length; j++)
{
//alert(sel.options[j].text);
var a = sel.options[i].text;
var b = sel.options[j].text;
//alert("a="+a);
//alert("b="+b);
if (a == b)
{
sel.remove(j);
back();
}
}
}
}
catch(e){
alert(e+"NO Route In The table");
}
}
</script>
<!-- End JavaScript To Eliminate Similar Station Names Generated From BackEnd -->
</td>
<tr>
<td>
Destination Station
</td>
<td>
<select id="select2" name="destid" onchange="extract()">
<option value="0">--Please Select--</option>
<%
String s_sta=request.getParameter("value");
String sql2 ="select * from route_main where s_station_name='"+s_sta+"'";
pstmt = con.prepareStatement(sql2);
rs = pstmt.executeQuery();
while(rs.next()){
%>
<option value="<%=rs.getString(4)%>" ><%=rs.getString(5)%></option>
<%
}
%>
</select>
</td>
</tr>
</table>
<hr />
<br />
<!--
<h3> Trains Between a Pair Of Stations </h3>
<br />
<table border="1">
<tr>
<th rowspan="2"> Train No </th>
<th rowspan="2"> Train Name </th>
<th rowspan="2"> Type </th>
<th rowspan="2"> Origin </th>
<th rowspan="2"> Destination </th>
<th colspan="7"> Days Of Run </th>
</tr>
<tr>
<td> Mon</td>
<td> Tue</td>
<td> Wed</td>
<td> Thu</td>
<td> Fri</td>
<td> Sat</td>
<td> Sun</td>
</tr>
-->
<%
try{
int did=Integer.parseInt(request.getParameter("did"));
int sid = did - 99;
String sql3="select t.train_no, t.train_name, t.type, r.s_station_name, r.d_station_name, t.mon, t.tue, t.wed, t.thu, t.fri, t.sat, t.sun from train_info t, route_main r where t.s_station_id=r.s_station_id and t.s_station_id=? and t.d_station_id=?;";
pstmt = con.prepareStatement(sql3);
pstmt.setInt(1,sid);
pstmt.setInt(2,did);
rs = pstmt.executeQuery();
out.println("<h3> Trains Between a Pair Of Stations </h3>");
out.println("<br />");
out.println("<table border='1' bordercolor=#333333 style='color:white; font-weight: bold;'>");
out.println("<tr bgcolor=#333333>");
out.println("<th rowspan='2'> Train No </th>");
out.println("<th rowspan='2'> Train Name </th>");
out.println("<th rowspan='2'> Type </th>");
out.println("<th rowspan='2'> Origin </th>");
out.println("<th rowspan='2'> Destination </th>");
out.println("<th colspan='7'> Days Of Run </th>");
out.println("</tr>");
out.println("<tr bgcolor=#333333>");
out.println("<td> Mon</td>");
out.println("<td> Tue</td>");
out.println("<td> Wed</td>");
out.println("<td> Thu</td>");
out.println("<td> Fri</td>");
out.println("<td> Sat</td>");
out.println("<td> Sun</td>");
out.println("</tr>");
int flag=0;
while(rs.next()){
flag=1;
out.println("<tr style='color:blue; font-weight: bold;'>");
out.println("<td>"+ rs.getInt("train_no") +"</td>");
out.println("<td>"+ rs.getString("train_name") +"</td>");
out.println("<td>"+ rs.getString("type") +"</td>");
out.println("<td>"+ rs.getString("s_station_name") +"</td>");
out.println("<td>"+ rs.getString("d_station_name") +"</td>");
if(rs.getString("mon").equalsIgnoreCase("Y")){
out.println("<td><span style='color: green;font-weight: bold;'>");
}else{
out.println("<td><span style='color: red;font-weight: bold;'>");
}
out.println(rs.getString("mon") +"</span></td>");
if(rs.getString("tue").equalsIgnoreCase("Y")){
out.println("<td><span style='color: green;font-weight: bold;'>");
}else{
out.println("<td><span style='color: red;font-weight: bold;'>");
}
out.println(rs.getString("tue") +"</span></td>");
if(rs.getString("wed").equalsIgnoreCase("Y")){
out.println("<td><span style='color: green;font-weight: bold;'>");
}else{
out.println("<td><span style='color: red;font-weight: bold;'>");
}
out.println(rs.getString("wed") +"</span></td>");
if(rs.getString("thu").equalsIgnoreCase("Y")){
out.println("<td><span style='color: green;font-weight: bold;'>");
}else{
out.println("<td><span style='color: red;font-weight: bold;'>");
}
out.println(rs.getString("thu") +"</span></td>");
if(rs.getString("fri").equalsIgnoreCase("Y")){
out.println("<td><span style='color: green;font-weight: bold;'>");
}else{
out.println("<td><span style='color: red;font-weight: bold;'>");
}
out.println(rs.getString("fri") +"</span></td>");
if(rs.getString("sat").equalsIgnoreCase("Y")){
out.println("<td><span style='color: green;font-weight: bold;'>");
}else{
out.println("<td><span style='color: red;font-weight: bold;'>");
}
out.println(rs.getString("sat") +"</span></td>");
if(rs.getString("sun").equalsIgnoreCase("Y")){
out.println("<td><span style='color: green;font-weight: bold;'>");
}else{
out.println("<td><span style='color: red;font-weight: bold;'>");
}
out.println(rs.getString("sun") +"</span></td>");
out.println("</tr>");
%>
<span style="font-weight: bold;"></span>
<!-- <tr>
<td> <%= rs.getInt("train_no") %> </td>
<td> <%= rs.getString("train_name") %> </td>
<td> <%= rs.getString("type") %> </td>
<td> <%= rs.getString("s_station_name") %> </td>
<td> <%= rs.getString("d_station_name") %> </td>
<td> <%= rs.getString("mon") %> </td>
<td> <%= rs.getString("tue") %> </td>
<td> <%= rs.getString("wed") %> </td>
<td> <%= rs.getString("thu") %> </td>
<td> <%= rs.getString("fri") %> </td>
<td> <%= rs.getString("sat") %> </td>
<td> <%= rs.getString("sun") %> </td></tr>
-->
<%
}
out.println("</table>");
if(flag==0){
%>
<script type="text/javascript">
alert("No Trains Found");
</script>
<%
}
}catch(Exception e){
}
%>
<!--
</table>
-->
</form>
</div>
<!-- Form Body -->
</div> <!-- end of templatemo_content -->
<div id="templatemo_sidebar">
<div id="request_a_quote">
<%
try{
if(session.isNew()){ //session.isNew is true for the first time when the page is loaded
}
else{
String uname = (String)session.getAttribute("uname");
String ssid = (String)session.getAttribute("sid");
String author = (String)session.getAttribute("author");
String error = (String)session.getAttribute("error");
String sessionid = (String)session.getId();
if(error=="Y"){ //error=Y is set when the email and password are mismatched
}
else if(ssid == sessionid) { //To verify the session id of page and sid i.e session id set during session creation match
%>
<h2> Login Details</h2><br/>
<p style="font-size: 12pt">
<label style="color:#DD0000;"> UserName</label> <%= uname %> <br/>
<label style="color:#DD0000;"> Authority </label> <%= author.toUpperCase() %> <br/>
<br/>
<a href="<%= author%>home.jsp"> <%= author.toUpperCase() %> Home</a>
<a href='Logout.jsp'> Logout</a>
</p>
<%
}
else{ //if all cases fail login is prompted
}
}
}
catch(Exception e){
}
%>
</div>
<div id="sidebar_featured_project">
<div class="cleaner"></div>
<div class="cleaner"></div>
<div class="cleaner"></div>
<div class="cleaner"></div>
<h3>Information</h3>
<div class="right" >
<h6 ><a href="SearchTrain.jsp">Trains Btw Stations</a></h6>
<h6><a href="SearchSchedule.jsp">Train Schedules</a></h6>
<h6><a href="ViewFare.jsp">Fare List</a></h6>
<h6><a href="http://www.indianrail.gov.in" target="_new">Other Railway Websites </a></h6>
</div>
<div class="cleaner"></div>
</div>
<div class="cleaner"></div>
</div>
</div> <!-- end of wrapper -->
<div id="footer"></div>
<script src="js/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>