Java实现Web航空订票系统(servlet+jdbc+jsp+mysql)(下)

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介: Java实现Web航空订票系统(servlet+jdbc+jsp+mysql)

BookingServlet

package com.abs.servlet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.abs.db.DBName;
import com.abs.factory.DaoFactory;
import com.abs.model.FlightInfo;
public class BookingServlet extends HttpServlet {
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    this.doPost(request, response);
  }
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");
    String[] fIDList = request.getParameterValues("flightInfoID");
    List<FlightInfo> flightInfoList = new ArrayList<FlightInfo>();
    try {
      for (String idString : fIDList) { 
        FlightInfo flightInfo = DaoFactory.getFlightInfoDaoInstance(DBName.ABS).findByID(Integer.parseInt(idString));
        if(null != flightInfo){
          flightInfoList.add(flightInfo);
        }
      }
      //  discount of same airline
      if(flightInfoList.size() == 2){
        FlightInfo f1 = flightInfoList.get(0);
        FlightInfo f2 = flightInfoList.get(1);
        if(f1.getAirlineCode().equals(f2.getAirlineCode())){
          double discount = DaoFactory.getAirlineDaoInstance(DBName.ABS).findByCode(f1.getAirlineCode()).getDiscount();
          f2.setFare(f2.getFare() * discount); 
        }
      }
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    request.setAttribute("flightInfoList", flightInfoList); 
    request.getRequestDispatcher("/booking.jsp").forward(request,response);
  }
}

SearchServlet

package com.abs.servlet;
import java.io.IOException;
import java.sql.Date;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.abs.action.SearchAction;
import com.abs.model.FlightInfo;
public class SearchServlet extends HttpServlet {
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    this.doPost(request, response);
  }
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");
    String departureCity = request.getParameter("departureCity");
    String arrivalCity  = request.getParameter("arrivalCity");
    String departureDate = request.getParameter("departureDate");
    //String returnDate = request.getParameter("returnDate");
    request.setAttribute("currentDepartureCity", departureCity);
    request.setAttribute("currentArrivalCity", arrivalCity);
    request.setAttribute("currentDepartureDate", departureDate);
    //request.setAttribute("currentReturnDate", returnDate);
    List<FlightInfo> list = null;
    List<List<FlightInfo>> transferList = null;
    //  directly flight
    try {
      list = SearchAction.searchFlightDirectly(departureCity, arrivalCity, departureDate);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    if(list.size() > 0){
       Collections.sort(list,new Comparator<FlightInfo>(){
        @Override
        public int compare(FlightInfo o1, FlightInfo o2) {
          // TODO Auto-generated method stub
          return o1.getDepatureTime().compareTo(o2.getDepatureTime());
        }});
      request.setAttribute("list", list);
    }else {
      //  transfer flight
      try {
        transferList = SearchAction.searchFlightTransfer(departureCity, arrivalCity, departureDate);
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      if(transferList.size() > 0){
        Collections.sort(transferList,new Comparator<List<FlightInfo>>(){
          @Override
          public int compare(List<FlightInfo> o1, List<FlightInfo> o2) {
            // TODO Auto-generated method stub
            return o1.get(0).getDepatureTime().compareTo(o2.get(0).getDepatureTime());
          }});
        request.setAttribute("transferList", transferList);
      }else{
        //  显示没有结果
        request.setAttribute("noResult", "noResult");
      }
      // ******* test only ********  transfer path
      for (List<FlightInfo> list2 : transferList) {
        for (FlightInfo flightInfo : list2) {
          System.out.println(flightInfo.getDepatureAirportCity() + " " + flightInfo.getArrivalAirportCity());
        }
        System.out.println("***********************");
      }
    }
    request.getRequestDispatcher("/resultList.jsp").forward(request,response);
  }
}

AirlineService

package com.abs.service;
import java.util.List;
import com.abs.dao.AirlineDao;
import com.abs.dao.impl.AirlineDaoImpl;
import com.abs.db.DBConnection;
import com.abs.db.DBName;
import com.abs.model.Airline;
public class AirlineService implements AirlineDao {
  private DBConnection dbconn = null;
  private AirlineDao  AirlineDao = null;
  private AirlineDao  ABSDao = null;
  public AirlineService(DBName dbName) throws Exception {
    // TODO Auto-generated constructor stub
    this.dbconn = new DBConnection();
    this.AirlineDao = new AirlineDaoImpl(dbconn.getConnection(dbName));
    this.ABSDao = new AirlineDaoImpl(dbconn.getConnection(DBName.ABS));
  }
  @Override
  public boolean add(Airline airline) throws Exception {
    // TODO Auto-generated method stub
    boolean airlineFlag = false;
    boolean ABSFlag = false;
    try {
      airlineFlag = this.AirlineDao.add(airline);
      ABSFlag = this.ABSDao.add(airline);
    } catch (Exception e) {
      // TODO: handle exception
      throw e;
    }finally {
      this.dbconn.closeAll();
    }
    return (airlineFlag && ABSFlag);
  }
  @Override
  public Airline findByCode(String code) throws Exception {
    // TODO Auto-generated method stub
    Airline airline = null;
    try {
      airline = this.ABSDao.findByCode(code);
    } catch (Exception e) {
      // TODO: handle exception
      throw e;
    }finally {
      this.dbconn.closeAll();
    }
    return airline;
  }
  @Override
  public List<Airline> findAll() throws Exception {
    // TODO Auto-generated method stub
    List<Airline> list = null;
    try {
      list = this.ABSDao.findAll();
    } catch (Exception e) {
      // TODO: handle exception
      throw e;
    }finally {
      this.dbconn.closeAll();
    }
    return list;
  }
}

FlightInfoService

package com.abs.service;
import java.sql.Date;
import java.sql.Time;
import java.util.List;
import com.abs.dao.FlightInfoDao;
import com.abs.dao.impl.FlightInfoDaoImpl;
import com.abs.db.DBConnection;
import com.abs.db.DBName;
import com.abs.model.FlightInfo;
public class FlightInfoService implements FlightInfoDao {
  private DBConnection dbconn = null;
  private FlightInfoDao dao = null;
  public FlightInfoService(DBName dbName) throws Exception {
    // TODO Auto-generated constructor stub
    this.dbconn = new DBConnection();
    this.dao = new FlightInfoDaoImpl(dbconn.getConnection(dbName));
  }
  @Override
  public boolean add(FlightInfo flightInfo) throws Exception {
    // TODO Auto-generated method stub
    boolean flag = false;
    try {
      flag = this.dao.add(flightInfo);
    } catch (Exception e) {
      // TODO: handle exception
      throw e;
    }finally {
      this.dbconn.closeAll();
    }
    return flag;
  }
  @Override
  public FlightInfo findByID(int id) throws Exception {
    // TODO Auto-generated method stub
    FlightInfo flightInfo = null;
    try {
      flightInfo = this.dao.findByID(id);
    } catch (Exception e) {
      // TODO: handle exception
      throw e;
    }finally {
      this.dbconn.closeAll();
    }
    return flightInfo;
  }
  @Override
  public List<FlightInfo> findByAirport(String depatureAirportCity, String arrivalAirportCity, Date depatureDate) throws Exception {
    // TODO Auto-generated method stub
    List<FlightInfo> list = null;
    try {
      list = this.dao.findByAirport(depatureAirportCity, arrivalAirportCity, depatureDate);
    } catch (Exception e) {
      // TODO: handle exception
      throw e;
    }finally {
      this.dbconn.closeAll();
    }
    return list;
  }
  @Override
  public List<FlightInfo> findByDepatureAirport(String depatureAirportCity, Date depatureDate) throws Exception {
    // TODO Auto-generated method stub
    List<FlightInfo> list = null;
    try {
      list = this.dao.findByDepatureAirport(depatureAirportCity, depatureDate);
    } catch (Exception e) {
      // TODO: handle exception
      throw e;
    }finally {
      this.dbconn.closeAll();
    }
    return list;
  }
  @Override
  public List<FlightInfo> findByTransferArrivalAirport(String depatureAirportCity, String arrivalAirportCity, Date depatureDate, Time depatureTime) throws Exception {
    // TODO Auto-generated method stub
    List<FlightInfo> list = null;
    try {
      list = this.dao.findByTransferArrivalAirport(depatureAirportCity, arrivalAirportCity, depatureDate,depatureTime);
    } catch (Exception e) {
      // TODO: handle exception
      throw e;
    }finally {
      this.dbconn.closeAll();
    }
    return list;
  }
  @Override
  public int addPassenger(int id) throws Exception {
    // TODO Auto-generated method stub
    int emptySeats = -1;
    try {
      emptySeats = this.dao.addPassenger(id);
    } catch (Exception e) {
      // TODO: handle exception
      throw e;
    }finally {
      this.dbconn.closeAll();
    }
    return emptySeats;
  }
}

booking.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>  
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>ABS_Booking</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <base href="<%=basePath%>">
  <link rel="SHORTCUT ICON" href="<%=path %>/images/airplane.icon"/>
  <link rel="stylesheet" href="<%=path %>/css/cube.css">
  <link rel="SHORTCUT ICON" href="<%=path %>/images/airplane.icon"/>
  <link rel="stylesheet" type="text/css" href="<%=path %>/css/absBase.css">
  <link rel="stylesheet" type="text/css" href="<%=path %>/css/booking.css">
  <script type="text/javascript" src="js/booking.js"></script>
</head>
<body>
  <div class="abs_container clearfix b_container">
    <form action="servlet/OrderServlet" method="post" class="b_form">
      <span class="b_form_title">乘客</span>
      <div id="b_formItem_container">
        <div class="b_form_item clearfix">
          <div class="bf_item_idArea">
            <span class="bf_item_id">1</span>
          </div>
          <div class="bf_item_textArea">
            <div class="bf_item_text clearfix">
              <span>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名:</span>
              <div>
                <input type="text" name="name" onfocus="textOnFocus(this)" onblur="textOnBlur(this)">
              </div>
            </div>
            <div class="bf_item_text clearfix">
              <span>护&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;照:</span>
              <div>
                <input type="text" name="passport" onfocus="textOnFocus(this)" onblur="textOnBlur(this)">
              </div>
            </div>
            <div class="bf_item_seatType">
              <span>座位偏好:</span>
              <label class="user_unSelect">
                <input class="bf_item_radioBut" type="radio" checked="checked" name="seatType1" value="default"/>默认
              </label>
              <label class="user_unSelect">
                <input class="bf_item_radioBut" type="radio" name="seatType1" value="windowSeat"/>靠窗
              </label>
              <label class="user_unSelect">
                <input class="bf_item_radioBut" type="radio" name="seatType1" value="middleSeat"/>中间
              </label>
              <label class="user_unSelect">
                <input class="bf_item_radioBut" type="radio" name="seatType1" value="aisleSeat"/>靠过道
              </label>
            </div>
          </div>
          <div class="bf_item_subtotalArea">
            <div class="bf_item_delete clearfix">
              <span onclick="deleteItem(this)">删除</span>
              <img src="images/close_icon.png" onclick="deleteItem(this)">
            </div>
            <div class="bf_item_subtotal">
              <c:forEach items="${flightInfoList}" var="flightInfo">
                <span>¥
                  <fmt:formatNumber type="number" groupingUsed="false" value="${flightInfo.fare}" />
                </span>
              </c:forEach>
            </div>
          </div>
        </div>
      </div>
      <!-- other form_item -->
      <div>
        <button class="b_form_addItem" type="button" onclick="addItem()">+ 添加乘客</button>
      </div>
      <div class="b_form_mainPassenger">
        <span class="b_form_title">联系人</span>
        <div class="bf_passenger_info clearfix">
          <div class="bfp_info_text">
            <span>姓&nbsp;&nbsp;名:</span>
              <div>
                <input type="text" name="contact" onfocus="textOnFocus(this)" onblur="textOnBlur(this)">
              </div>
            </div>
            <div class="bfp_info_text">
              <span>手机号:</span>
              <div>
                <input type="text" name="phone" onfocus="textOnFocus(this)" onblur="textOnBlur(this)">
              </div>
            </div>
          </div>
        </div>
      <c:forEach items="${flightInfoList}" var="flightInfo">
        <input type="hidden" name="flightInfoID" value="${flightInfo.id}">
      </c:forEach>
      <div>
        <input class="b_form_submit" type="submit" name="submitButton" value="提交订单">
      </div>
    </form>
    <div class="b_order">
      <c:set var="totalFare" value="0"/>
      <div class="b_order_info">
        <c:forEach items="${flightInfoList}" var="flightInfo">
          <div class="bo_info_item">
            <div class="bo_info_flightArea">
              <span class="bo_info_num"></span>
                <span class="bo_info_date">
                  <fmt:formatDate value="${flightInfo.depatureDate}" type="both" pattern="MM-dd"/>
                </span>
              <span class="bo_info_city">${flightInfo.depatureAirportCity}</span>
              <img class="bo_info_arrow" src="images/info_arrow_icon.png">
              <span class="bo_info_city">${flightInfo.arrivalAirportCity}</span>
            </div>
            <div class="bo_info_airlineArea">
              <span class="bo_info_airline">${flightInfo.airlineName} ${flightInfo.airlineCode}${flightInfo.number}</span>
              <span class="bo_info_plane">${flightInfo.airplaneName}</span>
            </div>
            <div class="bo_info_timeArea clearfix">
              <span class="bo_info_time">
                <fmt:formatDate value="${flightInfo.depatureTime}" type="both" pattern="HH:mm"/>
              </span>
              <img src="images/info_costTime_icon.png">
              <span class="bo_info_costTime"></span>
              <span class="bo_info_time">
                <fmt:formatDate value="${flightInfo.arrivalTime}" type="both" pattern="HH:mm"/>
              </span>
            </div>
            <div class="bo_info_airportArea">
              <span class="bo_info_airport">${flightInfo.depatureAirportName}</span>
              <img class="bo_info_timeline" src="images/info_timeline_icon.png">
              <span class="bo_info_airport">${flightInfo.arrivalAirportName}</span>
            </div>
          </div>
        </c:forEach>
      </div>
      <div class="b_order_detail">
        <c:forEach items="${flightInfoList}" var="flightInfo">
          <div class="bo_detail_item">
            <div class="bo_detail_subtotal clearfix">
              <span class="bo_detail_title">机票</span>
              <span class="bo_detail_value">¥
                <span class="bo_detail_fare">
                  <fmt:formatNumber type="number" groupingUsed="false" value="${flightInfo.fare}" />
                  <c:set var="totalFare" value="${totalFare + flightInfo.fare}"/>
                </span> 
                 &times;
                <span class="bo_detail_num">1</span>
              </span>
            </div>
          </div>
        </c:forEach>
      </div>
      <div class="b_order_cost">
        <span id="o_totalFare">
          <fmt:formatNumber type="number" groupingUsed="false" value="${totalFare}" />
        </span>
      </div>
    </div>
  </div>
  <!-- form_item template; display none -->
  <div id="b_formItem">
    <div class="b_form_item clearfix">
      <div class="bf_item_idArea">
        <span class="bf_item_id">${num}</span>
      </div>
      <div class="bf_item_textArea">
        <div class="bf_item_text clearfix">
          <span>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名:</span>
          <div>
            <input type="text" name="name" onfocus="textOnFocus(this)" onblur="textOnBlur(this)">
          </div>
        </div>
        <div class="bf_item_text clearfix">
          <span>护&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;照:</span>
          <div>
            <input type="text" name="passport" onfocus="textOnFocus(this)" onblur="textOnBlur(this)">
          </div>
        </div>
        <div class="bf_item_seatType">
          <span>座位偏好:</span>
          <label>
            <input class="bf_item_radioBut" type="radio" checked="checked" name="seatType1" value="default" id="b_seat_default" />默认
          </label>
          <label>
            <input class="bf_item_radioBut" type="radio" name="seatType1" value="windowSeat" id="b_seat_widnow" />靠窗
          </label>
          <label>
            <input class="bf_item_radioBut" type="radio" name="seatType1" value="middleSeat" id="b_seat_middle" />中间
          </label>
          <label>
            <input class="bf_item_radioBut" type="radio" name="seatType1" value="aisleSeat" id="b_seat_aisle" />靠过道
          </label>
        </div>
      </div>
      <div class="bf_item_subtotalArea">
        <div class="bf_item_delete clearfix">
          <span onclick="deleteItem(this)">删除</span>
          <img src="images/close_icon.png" onclick="deleteItem(this)">
        </div>
        <div class="bf_item_subtotal">
          <c:forEach items="${flightInfoList}" var="flightInfo">
            <span>¥
              <fmt:formatNumber type="number" groupingUsed="false" value="${flightInfo.fare}" />
            </span>
          </c:forEach>
        </div>
      </div>
    </div>
  </div>
</body>
</html>

generateOrder.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>ABS_GenerateOrder</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <base href="<%=basePath%>">
  <link rel="SHORTCUT ICON" href="<%=path %>/images/airplane.icon"/>
  <link rel="stylesheet" href="<%=path %>/css/cube.css">
  <link rel="SHORTCUT ICON" href="<%=path %>/images/airplane.icon"/>
  <link rel="stylesheet" type="text/css" href="<%=path %>/css/absBase.css">
  <link rel="stylesheet" type="text/css" href="<%=path %>/css/generateOrder.css">
  <script type="text/javascript" src="<%=path %>/js/generateOrder.js"></script>
</head>
<body>
  <div class="abs_container clearfix g_container">
    <div class="g_order clearfix">
      <div class="g_title">
        <span>订单信息</span>
      </div>
      <div class="g_content">
        <div class="g_order_info">
          <div class="go_info_detail">
            <div class="go_info_title">
              <span>订单状态</span>
              <span>订单号</span>
              <span>预定日期</span>
              <span>预定方式</span>
              <span>支付方式</span>
            </div>
            <div class="go_info_value">
              <span class="go_info_styleBlod">已出票</span>
              <span class="go_info_styleBlod">${order.id}</span>
              <span>
                <fmt:formatDate value="${order.createDate}" type="both" pattern="yyyy-MM-dd"/>&nbsp;
                <fmt:formatDate value="${order.createTime}" type="both" pattern="HH:mm:ss"/>
              </span>
              <span>网上预定</span>
              <span>支付宝</span>
            </div>
          </div>
          <div class="go_info_total">
            <span>总金额</span>
            <em>¥</em>
            <span>
              <fmt:formatNumber type="number" groupingUsed="false" value="${order.totalFare}" />
            </span>
          </div>
        </div>
      </div>
      <div class="g_extend">
        <button class="go_extend_but" type="button">打印订单</button>
        <button class="go_extend_but go_eb_cancel" type="button">取消订单</button>
      </div>
    </div>
    <div class="g_flight clearfix">
      <div class="g_title">
        <span>航班</span>
      </div>
      <div class="g_content">
        <div class="g_flight_info">
          <c:set var="count" value="0"/>
            <c:forEach items="${flightInfoList}" var="flightInfo">
            <c:set var="count" value="${count + 1}"/>
          </c:forEach>
          <c:forEach items="${flightInfoList}" var="flightInfo" varStatus="currentStatus">
              <c:if test="${currentStatus.count == 1}">
                <div class="gf_info_title">
                  <c:if test="${count <=1}">
                    <span>单程</span>
                  </c:if>
                  <c:if test="${count > 1}">
                    <span>转机</span>
                  </c:if>
                </div>
              </c:if>
              <c:if test="${currentStatus.count != 1}">
                <div class="gf_info_title">
                  <span></span>
                </div>
              </c:if>
              <div class="gf_info_value">
                <div class="gf_info_item">
                  <div class="gf_info_main">
                    <span>
                      <fmt:formatDate value="${flightInfo.depatureDate}" type="both" pattern="yyyy-MM-dd"/>
                    </span>
                    <span>${flightInfo.depatureAirportCity}—${flightInfo.arrivalAirportCity}</span>
                  </div>
                  <div class="gf_info_detail">
                    <div class="gf_info_airline">
                      <span>${flightInfo.airlineName}</span>
                      <span>${flightInfo.airlineCode}${flightInfo.number}</span>
                      <span>${flightInfo.airplaneName}</span>
                    </div>
                    <div class="gf_info_time">
                      <div class="gf_info_depart">
                        <span class="gfi_time">
                          <fmt:formatDate value="${flightInfo.depatureTime}" type="both" pattern="HH:mm"/>
                        </span>
                        <span>${flightInfo.depatureAirportName}</span>
                      </div>
                      <img src="images/result_arrow.png">
                      <div class="gf_info_arrive">
                        <span class="gfi_time">
                          <fmt:formatDate value="${flightInfo.arrivalTime}" type="both" pattern="HH:mm"/>
                        </span>
                        <span>${flightInfo.arrivalAirportName}</span>
                      </div>
                      <div class="gf_info_costTime">
                        <img src="images/g_costTime_icon.png">
                        <span class="gfi_costTime"></span>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
          </c:forEach>
        </div>
      </div>
      <div class="g_extend"></div>
    </div>
    <div class="g_passenger clearfix">
      <div class="g_title">
        <span>乘机人</span>
      </div>
      <div class="g_content">
        <div class="g_passenger_info">
          <c:forEach items="${passengers}" var="passenger" varStatus="currentStatus">
            <div class="gp_info_item">
              <div class="gp_info_num">
                <span>${currentStatus.count}</span>
              </div>
              <div class="gp_info_title">
                <span>姓名</span>
                <span>证件信息</span>
              </div>
              <div class="gp_info_value">
                <span>${passenger.name}</span>
                <span>护照&nbsp;&nbsp;${passenger.passport}</span>
              </div>
            </div>
          </c:forEach>
        </div>
      </div>
      <div class="g_extend"></div>
    </div>
    <div class="g_contact clearfix">
      <div class="g_title">
        <span>联系人</span>
      </div>
      <div class="g_content">
        <div class="g_passenger_info">
          <div class="g_contact_left">
          </div>
          <div class="gp_contact_item">
            <div class="gp_info_title">
              <span>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名</span>
              <span>联系方式</span>
            </div>
            <div class="gp_info_value">
              <span>${order.contactName}</span>
              <span>${order.contactPhone}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="g_extend"></div>
    </div>
  </div>
</body>
</html>

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>ABS_Search</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <base href="<%=basePath%>">
  <link rel="SHORTCUT ICON" href="<%=path %>/images/airplane.icon"/>
  <link rel="stylesheet" href="<%=path %>/css/cube.css">
  <link rel="SHORTCUT ICON" href="<%=path %>/images/airplane.icon"/>
  <link rel="stylesheet" type="text/css" href="<%=path %>/css/absBase.css">
  <link rel="stylesheet" type="text/css" href="<%=path %>/css/search.css">
  <script type="text/javascript" src="<%=path %>/js/search.js"></script>
</head>
<body>
  <div class="s_box">
    <form action="servlet/SearchServlet" method="post" class="s_box_container">
      <div class="s_row s_tab_line clearfix">
        <button type="button" class="s_tab">国内机票</button>
        <button type="button" class="s_tab">国际机票</button>
      </div>
      <div class="s_row">
        <span class="s_label">航行类型</span>
        <label for="s_radio_oneWay" class="user_unSelect">
          <input class="s_radioBut" type="radio" name="tripType" value="oneWay" id="s_radio_oneWay" checked="checked" onclick="radioButClick(this)">单程
        </label>
        <label for="s_radio_roundTrip" class="user_unSelect">
          <input class="s_radioBut" type="radio" name="tripType" value="roundTrip" id="s_radio_roundTrip" onclick="radioButClick(this)">往返
        </label>
      </div>
      <div class="s_row">
        <span class="s_label">出发城市</span>
        <!-- <input class="s_text" type="text" name="departureCity"> -->
        <select class="s_text" name="departureCity">
          <option></option>
          <option value ="武汉">武汉</option>
          <option value ="北京">北京</option>
          <option value ="上海">上海</option>
          <option value ="广州">广州</option>
          <option value ="深圳">深圳</option>
          <option value ="成都">成都</option>
          <option value ="沈阳">沈阳</option>
          <option value ="西藏">西藏</option>
        </select>
        <span class="s_label">出发日期</span>
        <input id="dDate" class="s_text s_date" type="date" name="departureDate">
      </div>
      <div class="s_row">
        <span class="s_label">到达城市</span>
        <!-- <input class="s_text" type="text" name="arrivalCity"> -->
        <select class="s_text" name="arrivalCity">
          <option></option>
          <option value ="北京">北京</option>
          <option value ="武汉">武汉</option>
          <option value ="上海">上海</option>
          <option value ="广州">广州</option>
          <option value ="深圳">深圳</option>
          <option value ="成都">成都</option>
          <option value ="沈阳">沈阳</option>
          <option value ="西藏">西藏</option>
        </select>
        <span class="s_label">返回日期</span>
        <input id="aDate" class="s_text s_date" type="date" name="returnDate" id="s_returnDate" disabled="disabled">
      </div>
      <div class="s_row">
        <input  class="s_submit" type="submit" value="搜索机票">
      </div>
    </form>
  </div>
</body>
</html>

resultList.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>ABS_ResultList</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <base href="<%=basePath%>">
  <link rel="SHORTCUT ICON" href="<%=path %>/images/airplane.icon"/>
  <link rel="stylesheet" href="css/cube.css">
  <link rel="stylesheet" type="text/css" href="<%=path %>/css/absBase.css">
  <link rel="stylesheet" type="text/css" href="<%=path %>/css/resultList.css">
  <script type="text/javascript" src="<%=path %>/js/reslutList.js"></script>
</head>
<body onload="InitSelect('${currentDepartureCity}', '${currentArrivalCity}')">
  <div class="abs_container clearfix r_container" id="tripItemContainer">
    <form action="servlet/SearchServlet" method="post" class="r_top clearfix">
      <select class="r_top_select" onchange="selectChange(this)">
        <option value ="oneWay">单程</option>
        <option value ="roundTrip">往返</option>
      </select>
      <div class="r_top_text">
        <img class="r_icon" src="images/departure_icon.png">
        <!-- <input type="text" name="departureCity" placeholder="出发城市" οnfοcus="textOnFocus(this)" οnblur="textOnBlur(this)" value="${currentDepartureCity}"> -->
        <select id="departureSelect" name="departureCity" onfocus="textOnFocus(this)" onblur="textOnBlur(this)" >
          <option></option>
          <option value ="武汉">武汉</option>
          <option value ="北京">北京</option>
          <option value ="上海">上海</option>
          <option value ="广州">广州</option>
          <option value ="深圳">深圳</option>
          <option value ="成都">成都</option>
          <option value ="沈阳">沈阳</option>
          <option value ="西藏">西藏</option>
        </select>
      </div>
      <div class="r_top_text">
        <img class="r_icon" src="images/departure_time_icon.png">
        <!-- <input type="text" name="arrivalCity" placeholder="到达城市" οnfοcus="textOnFocus(this)" οnblur="textOnBlur(this)" value="${currentArrivalCity}"> -->
        <select id="arrivalSelect" name="arrivalCity" onfocus="textOnFocus(this)" onblur="textOnBlur(this)" >
          <option></option>
          <option value ="武汉">武汉</option>
          <option value ="北京">北京</option>
          <option value ="上海">上海</option>
          <option value ="广州">广州</option>
          <option value ="深圳">深圳</option>
          <option value ="成都">成都</option>
          <option value ="沈阳">沈阳</option>
          <option value ="西藏">西藏</option>
        </select>
      </div>
      <div class="r_top_text">
        <img class="r_icon" src="images/desi_icon.png">
        <input id="dDate" type="date" name="departureDate" onfocus="textOnFocus(this)" onblur="textOnBlur(this)" value="${currentDepartureDate}">
      </div>
      <div class="r_top_text">
        <img class="r_icon" src="images/desi_time_icon.png">
        <input id="aDate" type="date" name="returnDate" onfocus="textOnFocus(this)" onblur="textOnBlur(this)" id="s_returnDate" disabled="disabled">
      </div>
      <input class="r_top_but" type="submit" value="重新搜索">
    </form>
    <div class="r_title clearfix" id="r_title">
      <span class="r_title_header">航班信息</span>
      <label id="r_label_1" class="r_title_item1 user_unSelect" onclick="changeSortType('r_label_1')">
        <span>起飞时间</span>
        <div class="r_title_sortIcon">
          <img src="images/icon_up_blue.png">
          <img src="images/icon_down_gray.png">
        </div>
      </label>
      <label id="r_label_2" class="r_title_item2 user_unSelect" onclick="changeSortType('r_label_2')">
        <span>到达时间</span>
        <div class="r_title_sortIcon">
          <img src="images/icon_up_gray.png">
          <img src="images/icon_down_gray.png">
        </div>
      </label>
      <label id="r_label_3" class="r_title_item3 user_unSelect" onclick="changeSortType('r_label_3')">
        <span>价格</span>
        <div class="r_title_sortIcon">
          <img src="images/icon_up_gray.png">
          <img src="images/icon_down_gray.png">
        </div>
      </label>
    </div>
    <!-- result list area -->
    <%-- 直达航班 --%>
    <c:forEach items="${list}" var="item" varStatus="current">
      <div class="r_resultItem clearfix tripItem">
        <div class="r_resultItemBox clearfix">
          <div class="r_result_col width_20"></div>
          <div class="r_result_col width_180">
            <span class="r_airline">${item.airlineName}  <span>${item.airlineCode}${item.number}</span></span> 
            <span class="r_airplane">${item.airplaneName} </span>
          </div>
          <div class="r_result_col width_140">
            <span class="r_departureTime">
              <fmt:formatDate value="${item.depatureTime}" type="both" pattern="HH:mm"/>
            </span>
            <span class="r_departureCity">${item.depatureAirportName}</span>
          </div>
          <div class="r_result_col width_100">
            <img class="r_arrow" src="images/result_arrow.png">
          </div>
          <div class="r_result_col width_140">
            <span class="r_destinationTime">
              <fmt:formatDate value="${item.arrivalTime}" type="both" pattern="HH:mm"/>
            </span>
            <span class="r_destinationCity">${item.arrivalAirportName}</span>
          </div>
          <div class="r_result_col width_150 r_detail">
            <span>
              <fmt:formatNumber type="number" groupingUsed="false" value="${item.fare}" />
               * ${1}
            </span>
          </div>
          <div class="r_result_col width_150">
            <span class="r_price">¥
              <span>
                <fmt:formatNumber type="number" groupingUsed="false" value="${item.fare}" />
              </span>
            </span>
          </div>
          <div class="r_result_col width_100">
            <form action="servlet/BookingServlet" method="post" class="r_button_box">
              <%-- 提交被选中的 FlightInfo的 id --%>
              <input type="hidden" name="flightInfoID" value="${item.id}">
              <input  class="r_button" type="submit" value="提交">
              <c:if test="${item.airplaneEmptySeats < 10}">
                <span class="r_emptySeats">${item.airplaneEmptySeats}张</span>
              </c:if>
            </form>
          </div>
        </div>
      </div>
    </c:forEach>
    <%-- 中转组合航班 --%>
    <c:forEach items="${transferList}" var="listItem" varStatus="current">
      <div class="r_resultItem clearfix tripItem">
        <div class="r_resultItemBox clearfix">
          <div class="r_result_col width_20"></div>
          <div class="r_result_col width_180">
            <c:forEach items="${listItem}" var="item" begin="0" end="0">
              <span class="r_airline">${item.airlineName} <span>${item.airlineCode}${item.number}</span></span> 
            </c:forEach>
            <c:forEach items="${listItem}" var="item" begin="1" end="1">
              <span class="r_airline">${item.airlineName} <span>${item.airlineCode}${item.number}</span></span> 
            </c:forEach>
          </div>
          <div class="r_result_col width_140">
            <c:forEach items="${listItem}" var="item" begin="0" end="0">
              <span class="r_departureTime">
                <fmt:formatDate value="${item.depatureTime}" type="both" pattern="HH:mm"/>
              </span>
              <span class="r_departureCity">${item.depatureAirportName}</span>
            </c:forEach>
          </div>
          <div class="r_result_col width_100">
            <span class="r_transfer1_trans1">经停</span>
            <img class="r_transfer1_arrow" src="images/result_arrow.png">
            <c:forEach items="${listItem}" var="item" begin="0" end="0">
              <span class="r_transfer1_trans2">${item.arrivalAirportCity}</span>
            </c:forEach>
          </div>
          <div class="r_result_col width_140">
            <c:forEach items="${listItem}" var="item" begin="1" end="1">
              <span class="r_destinationTime">
                <fmt:formatDate value="${item.arrivalTime}" type="both" pattern="HH:mm"/>
              </span>
              <span class="r_destinationCity">${item.arrivalAirportName}</span>
            </c:forEach>
          </div>
          <div class="r_result_col width_150">
            <c:forEach items="${listItem}" var="item" begin="0" end="0">
              <span class="r_transfer1_fare">
                <fmt:formatNumber type="number" groupingUsed="false" value="${item.fare}" />
                * 1
               </span>
               <c:set var="fare1" value="${item.fare}"/>
            </c:forEach>
            <c:forEach items="${listItem}" var="item" begin="1" end="1">
              <span class="r_transfer1_fare">
                <fmt:formatNumber type="number" groupingUsed="false" value="${item.fare}" />
                * 1
               </span>
               <c:set var="fare2" value="${item.fare}"/>
            </c:forEach>
          </div>
          <div class="r_result_col width_150">
            <span class="r_price">
              <span>
                <fmt:formatNumber type="number" groupingUsed="false" value="${fare1 + fare2}" />
              </span>
            </span>
          </div>
          <div class="r_result_col width_100">
            <form action="servlet/BookingServlet" method="post" class="r_button_box">
              <%-- 提交被选中的 FlightInfo的 id --%>
              <c:forEach items="${listItem}" var="item">
                <input type="hidden" name="flightInfoID" value="${item.id}">
              </c:forEach>
              <input  class="r_button" type="submit" value="提交">
              <c:forEach items="${listItem}" var="item" begin="0" end="0">
                <c:set var="seat1" value="${item.airplaneEmptySeats}"/>
              </c:forEach>
              <c:forEach items="${listItem}" var="item" begin="1" end="1">
                <c:set var="seat2" value="${item.airplaneEmptySeats}"/>
              </c:forEach>
              <c:if test="${(seat1<seat2?seat1:seat2) < 10}">
                <span class="r_emptySeats">${seat1<seat2?seat1:seat2}张</span>
              </c:if>
            </form>
          </div>
        </div>
      </div>
    </c:forEach>
    <c:if test="${noResult == 'noResult'}">
      <div class="r_noResult">
        <span>抱歉! 没有查询到结果</span>
      </div>
    </c:if>
  </div>
</body>
</html>


四、其他


1.其他系统实现


JavaWeb系统系列实现

Java+JSP实现学生图书管理系统

Java+JSP实现学生信息管理系统

Java+JSP实现用户信息管理系统

Java+Servlet+JSP实现学生成绩管理系统

Java+Servlet+JSP实现宠物诊所管理系统

Java+SSM+Easyui实现网上考试系统

Java+Springboot+H-ui实现营销管理系统

Java+Springboot+Mybatis+Bootstrap实现网上商城系统


JavaSwing系统系列实现

Java+Swing实现斗地主游戏

Java+Swing实现图书管理系统

Java+Swing实现医院管理系统

Java+Swing实现仓库管理系统

Java+Swing实现考试管理系统

Java+Swing实现通讯录管理系统

Java+Swing实现停车场管理系统

Java+Swing实现学生信息管理系统

Java+Swing实现学生宿舍管理系统

Java+Swing实现学生选课管理系统

Java+Swing实现学生成绩管理系统

Java+Swing实现学校教材管理系统

Java+Swing实现学校教务管理系统

Java+Swing实现企业人事管理系统

Java+Swing实现电子相册管理系统

Java+Swing实现自助取款机(ATM)系统

Java+Swing实现超市管理系统-TXT存储信息

Java+Swing实现宠物商店管理系统-TXT存储信息


相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
2月前
|
关系型数据库 MySQL Java
【MySQL+java+jpa】MySQL数据返回项目的感悟
【MySQL+java+jpa】MySQL数据返回项目的感悟
45 1
|
2月前
|
关系型数据库 MySQL Java
【IDEA】java后台操作mysql数据库驱动常见错误解决方案
【IDEA】java后台操作mysql数据库驱动常见错误解决方案
93 0
|
7天前
|
NoSQL Java 关系型数据库
Liunx部署java项目Tomcat、Redis、Mysql教程
本文详细介绍了如何在 Linux 服务器上安装和配置 Tomcat、MySQL 和 Redis,并部署 Java 项目。通过这些步骤,您可以搭建一个高效稳定的 Java 应用运行环境。希望本文能为您在实际操作中提供有价值的参考。
60 26
|
11天前
|
JavaScript 安全 Java
java版药品不良反应智能监测系统源码,采用SpringBoot、Vue、MySQL技术开发
基于B/S架构,采用Java、SpringBoot、Vue、MySQL等技术自主研发的ADR智能监测系统,适用于三甲医院,支持二次开发。该系统能自动监测全院患者药物不良反应,通过移动端和PC端实时反馈,提升用药安全。系统涵盖规则管理、监测报告、系统管理三大模块,确保精准、高效地处理ADR事件。
|
21天前
|
关系型数据库 MySQL Java
MySQL索引优化与Java应用实践
【11月更文挑战第25天】在大数据量和高并发的业务场景下,MySQL数据库的索引优化是提升查询性能的关键。本文将深入探讨MySQL索引的多种类型、优化策略及其在Java应用中的实践,通过历史背景、业务场景、底层原理的介绍,并结合Java示例代码,帮助Java架构师更好地理解并应用这些技术。
23 2
|
27天前
|
监控 前端开发 Java
【技术开发】接口管理平台要用什么技术栈?推荐:Java+Vue3+Docker+MySQL
该文档介绍了基于Java后端和Vue3前端构建的管理系统的技术栈及功能模块,涵盖管理后台的访问、登录、首页概览、API接口管理、接口权限设置、接口监控、计费管理、账号管理、应用管理、数据库配置、站点配置及管理员个人设置等内容,并提供了访问地址及操作指南。
|
2月前
|
SQL Java 关系型数据库
java连接mysql查询数据(基础版,无框架)
【10月更文挑战第12天】该示例展示了如何使用Java通过JDBC连接MySQL数据库并查询数据。首先在项目中引入`mysql-connector-java`依赖,然后通过`JdbcUtil`类中的`main`方法实现数据库连接、执行SQL查询及结果处理,最后关闭相关资源。
115 6
|
2月前
|
关系型数据库 MySQL Java
java协程操作mysql数据库
本文介绍了如何在Java项目中使用虚拟线程和协程操作MySQL数据库,并通过代码示例展示了如何利用CompletableFuture实现非阻塞数据库连接和操作。
32 2
java协程操作mysql数据库
|
3月前
|
存储 关系型数据库 MySQL
【Java面试题汇总】MySQL数据库篇(2023版)
聚簇索引和非聚簇索引、索引的底层数据结构、B树和B+树、MySQL为什么不用红黑树而用B+树、数据库引擎有哪些、InnoDB的MVCC、乐观锁和悲观锁、ACID、事务隔离级别、MySQL主从同步、MySQL调优
【Java面试题汇总】MySQL数据库篇(2023版)
|
3月前
|
自然语言处理 算法 Java
Java如何判断两句话的相似度类型MySQL的match
【9月更文挑战第1天】Java如何判断两句话的相似度类型MySQL的match
28 2