27 Mayıs 2007 Pazar

A simple JSP File

A simple JSP file which gets results from request attributes and display them through iterations
----------------------------------------------

<%@page contentType="text/html" import="java.util.*, com.myairline.type.*" %>
<%@page pageEncoding="UTF-8"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="resources/style.css" rel="stylesheet" type="text/css">
<title>Flight Results</title>

</head>

<%
// Get and set attributes :::
ArrayList flightList1 = (ArrayList) request.getAttribute("flightList1");
ArrayList flightList2 = (ArrayList) request.getAttribute("flightList2");
int passengerCount = Integer.parseInt( (String) request.getAttribute( "passengerCount") );

%>

<body>

<!--------------------------------------------------------------------------------------------------------------------------
****************************************************************************************************************************
START FLIGHT SEARCH RESULTS FORM
****************************************************************************************************************************
------------------------------------------------------------------------------------------------------------------------ -->

<table border="1" cellspacing="4" cellpadding="4">

<thead>
<tr>
<th> Option </th>
<th> Flight No </th>
<th> Depart Date </th>
<th> From </th>
<th> To </th>
<th> Price </th>
</tr>
</thead>
<tbody>

<form name="flightSelectForm" method="post" action="/MyAirline/SearchServlet?cmd=selected_flight&source=customer">

<tr>
<td colspan="6">
<b> DEPART FLIGHTS RESULTS </b>
</td>
</tr>
<%
// Add Elements to Depart Flight Results List -
//************************************************************************************************************
Iterator flightIterator = flightList1.iterator();

boolean isEmpty1 = true;
while( flightIterator.hasNext() ) {
isEmpty1=false;
Flight currentFlight = (Flight) flightIterator.next();
%>

<tr>
<td>
<% out.println("<input type=\"radio\" name=\"flightSelection\" value=\""+ currentFlight.getFlightNo() +"\" />" ); %>
</td>

<td>
<%= currentFlight.getFlightNo()%>
</td>

<td>
<%= currentFlight.getFlightDate()%>
</td>

<td>
<%= currentFlight.getFlightRoute().getStartAirport().toString() %>
</td>

<td>
<%= currentFlight.getFlightRoute().getEndAirport().toString() %>
</td>

<td>
<%= currentFlight.getTicketFare()%>
</td>
</tr>

<%
} // end-while-
//************************************************************************************************************
%>

<%
if( isEmpty1 ) {
%>
<tr>
<td colspan="6" > NO MATCHING RESULTS </td>
</tr>
<%
} // -end-if-
%>

<tr>
<td colspan="6">
<b> RETURN FLIGHTS RESULTS </b>
</td>
</tr>

<%
boolean isEmpty2 = true;
if( flightList2 != null ) {
%>

<%
// Add Elements to Depart Flight Results List -
//************************************************************************************************************
Iterator flightIterator2 = flightList2.iterator();

isEmpty2 = true;
while( flightIterator2.hasNext() ) {
isEmpty2=false;
Flight currentFlight2 = (Flight) flightIterator2.next();
%>

<tr>
<td>
<% out.println("<input type=\"radio\" name=\"flightSelection2\" value=\""+ currentFlight2.getFlightNo() +"\" />" ); %>
</td>

<td>
<%= currentFlight2.getFlightNo()%>
</td>

<td>
<%= currentFlight2.getFlightDate()%>
</td>

<td>
<%= currentFlight2.getFlightRoute().getStartAirport().toString() %>
</td>

<td>
<%= currentFlight2.getFlightRoute().getEndAirport().toString() %>
</td>

<td>
<%= currentFlight2.getTicketFare()%>
</td>
</tr>

<%
} // end-while-
//************************************************************************************************************
%>

<%
} // -end-if-
%>


<%
if( isEmpty2 ) {
%>
<tr>
<td colspan="6" > NO MATCHING RESULTS </td>
</tr>
<%
} // -end-if-
%>

<% if( isEmpty1 == false ) { %>

<tr>
<td> Passenger Count: </td>
<td>
<%= passengerCount %>
</td>
</tr>

<input type="hidden" name="passengerCount" value="<%= passengerCount %>" />

<tr>
<td align=center colspan="36">
<A href="/MyAirline/SearchServlet?cmd=flight_search&source=agency" target="mainFrame"> SEARCH AGAIN </A>
</td>
</tr>
<tr>
<td colspan="6" align=center>
<input type="submit" value="CONTINUE TO PAYMENT" name="payment" />
</td>
</tr>

<%
} // -end-if-
%>


</form>

<!--------------------------------------------------------------------------------------------------------------------------
****************************************************************************************************************************
END FLIGHT SEARCH RESULTS FORM
****************************************************************************************************************************
------------------------------------------------------------------------------------------------------------------------ -->

</tbody>
</table>

</body>
</html>


Hiç yorum yok: