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

Posted 水坚石青

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java实现Web航空订票系统(servlet+jdbc+jsp+mysql)相关的知识,希望对你有一定的参考价值。

一、系统介绍

1.软件环境

Java:jdk1.8
Mysql:8.0.11
Tomcat:8.0.28

2.系统功能

机票查询
1.航行类型
2.出发城市
3.到达城市
4.出发日期
5.返回日期
选择航班
1.航班信息
2.起飞时间
3.到达时间
4.机票价格
填写乘客信息
1.姓名
2.护照
3.座位偏好
4.添加乘客
5.联系人
6.订单信息确认
7.提交订单
订单详情页
1.订单详细信息
2.航班详细信息
3.乘机人详细信息
4.联系人详细信息

3.数据库


/* create database */
drop database if exists AIRLINE_1;
drop database if exists AIRLINE_2;
drop database if exists AIRLINE_3;
drop database if exists ABS;

create database AIRLINE_1;
create database AIRLINE_2;
create database AIRLINE_3;
create database ABS;

/* create table of database Airline*/

use AIRLINE_1;

create table airline(
	code		varchar(3) 	not null	primary key,
    name		varchar(20)	not null,
    discount 	float(2,2)	not null
);

create table airport(
	code 		varchar(4)	not null	primary key,
    name		varchar(20)	not null,
    city		varchar(20)	not null,
    country		varchar(20)	not null,
    connTime	int(3)		not null	/* minute */
);

create table airplane(
    name		varchar(20)	not	null	primary key,
    type		varchar(10)	not null
);

create table seat(
	id			int(3)		not	null	primary key auto_increment,	
    relativeID	int(3)		not null,	/* 飞机上作为的相对编号 */
    row			int(3)		not null,
    num			int(3)		not null,
    type		varchar(12)	not	null,	/* windowSeat middleSeat aisleSeat*/
    flightID	int(10)		not null,	/* Table:airplane Item:id */
    passport	varchar(20)				/* passenger passport */
);

create table flight(
	id				int(10)		not	null	primary key,
    airlineCode 	varchar(3) 	not null,
    number			int(6)		not	null,
    depatureDate	Date		not null,
    depatureTime 	time		not	null,
    arrivalDate		Date		not null,
    arrivalTime		time		not	null,
    fare			float(6,2)	not	null,
    depatureAirport	varchar(4)	not	null,	/* Table:airport Item:code */
    arrivalAirport	varchar(4)	not	null,	/* Table:airport Item:code */
 	airplaneName	varchar(20)	not	null,	/* Table:airplane Item:name */
    airplaneType	varchar(10) not	null	/* Table:airplane Item:type */
);


use AIRLINE_2;

create table airline(
	code		varchar(3) 	not null	primary key,
    name		varchar(20)	not null,
    discount 	float(2,2)	not null
);

create table airport(
	code 		varchar(4)	not null	primary key,
    name		varchar(20)	not null,
    city		varchar(20)	not null,
    country		varchar(20)	not null,
    connTime	int(3)		not null	/* minute */
);

create table airplane(
    name		varchar(20)	not	null	primary key,
    type		varchar(10)	not null
);

create table seat(
	id			int(3)		not	null	primary key auto_increment,	
    relativeID	int(3)		not null,	/* 飞机上作为的相对编号 */
    row			int(3)		not null,
    num			int(3)		not null,
    type		varchar(12)	not	null,	/* windowSeat middleSeat aisleSeat*/
    flightID	int(10)		not null,	/* Table:airplane Item:id */
    passport	varchar(20)				/* passenger passport */
);

create table flight(
	id				int(10)		not	null	primary key,
    airlineCode 	varchar(3) 	not null,
    number			int(6)		not	null,
    depatureDate	Date		not null,
    depatureTime 	time		not	null,
    arrivalDate		Date		not null,
    arrivalTime		time		not	null,
    fare			float(6,2)	not	null,
    depatureAirport	varchar(4)	not	null,	/* Table:airport Item:code */
    arrivalAirport	varchar(4)	not	null,	/* Table:airport Item:code */
 	airplaneName	varchar(20)	not	null,	/* Table:airplane Item:name */
    airplaneType	varchar(10) not	null	/* Table:airplane Item:type */
);


use AIRLINE_3;

create table airline(
	code		varchar(3) 	not null	primary key,
    name		varchar(20)	not null,
    discount 	float(2,2)	not null
);

create table airport(
	code 		varchar(4)	not null	primary key,
    name		varchar(20)	not null,
    city		varchar(20)	not null,
    country		varchar(20)	not null,
    connTime	int(3)		not null	/* minute */
);

create table airplane(
    name		varchar(20)	not	null	primary key,
    type		varchar(10)	not null
);

create table seat(
	id			int(3)		not	null	primary key auto_increment,	
    relativeID	int(3)		not null,	/* 飞机上作为的相对编号 */
    row			int(3)		not null,
    num			int(3)		not null,
    type		varchar(12)	not	null,	/* windowSeat middleSeat aisleSeat*/
    flightID	int(10)		not null,	/* Table:airplane Item:id */
    passport	varchar(20)				/* passenger passport */
);

create table flight(
	id				int(10)		not	null	primary key,
    airlineCode 	varchar(3) 	not null,
    number			int(6)		not	null,
    depatureDate	Date		not null,
    depatureTime 	time		not	null,
    arrivalDate		Date		not null,
    arrivalTime		time		not	null,
    fare			float(6,2)	not	null,
    depatureAirport	varchar(4)	not	null,	/* Table:airport Item:code */
    arrivalAirport	varchar(4)	not	null,	/* Table:airport Item:code */
 	airplaneName	varchar(20)	not	null,	/* Table:airplane Item:name */
    airplaneType	varchar(10) not	null	/* Table:airplane Item:type */
);



/* create table of database ABS*/

use ABS;

create table airline(
	code		varchar(3)	not	null	primary key,
    name		varchar(20)	not	null,
    discount	float(2,2)	not	null
);

create table flightInfo(
	id				int(10)		not null	primary key  auto_increment,
	airlineCode		varchar(3)	not null,	/* Table:airline Item:code */
    flightID		int(10)		not	null,	/* Database:Airline Table:flight Item: */
    
    number			int(6)		not null,	/* Database:Airline Table:flight Item:number */
    depatureDate	Date		not null,	/* Database:Airline Table:flight Item:depatureDate */
    depatureTime 	time		not	null,	/* Database:Airline Table:flight Item:depatureTime */
    arrivalDate		Date		not null,	/* Database:Airline Table:flight Item:arrivalDate */
    arrivalTime		time		not	null,	/* Database:Airline Table:flight Item:arrivalTime */
    fare			float(6,2)	not	null,	/* Database:Airline Table:flight Item:fare */
    depatureAirport	varchar(4)	not	null,	/* Database:Airline Table:flight Item:depatureAirport */
    arrivalAirport	varchar(4)	not	null,	/* Database:Airline Table:flight Item:arrivalAirport */
    
	airlineName		varchar(20)	not null,	/* Table:airline Item:name */
    airplaneName	varchar(20)	not	null,	/* Database:Airline Table:airplane Item:name */
	airplaneType	varchar(10) not	null,	/* 大:240 中:160 小:80 */
	depatureAirportName		varchar(20)	not null,
    arrivalAirportName		varchar(20)	not null,
    depatureAirportCity		varchar(20)	not null,
    arrivalAirportCity		varchar(20)	not null,
    
    airplaneEmptySeats	int(3)	not	null	/* Database:Airline Table:airplane Item:conunt of empty seats */
);

create table airport(
	code 		varchar(4)	not null	primary key,
    name		varchar(20)	not null,
    city		varchar(20)	not null,
    country		varchar(20)	not null,
    connTime	int(3)		not null	/* minute */
);

create table passenger(
	passport	varchar(20)	not null,	/* no primary key for test */
    name		varchar(20)	not null	
);

create table trip(
	id				int(10)		not	null	primary key,
    flightInfoID	int(10)		not null,	/* Database:Airline Table:flight Item: */
    fare			float(6,2)	not null,	/* fare不同于 flightInfo中的 fare */
    passport		varchar(20)	not null,	/* Table:passenger Item:passport */
    seatID			int(3)		not null	/* Database:Airline Table:seat Item:relativeID */
);

create table orders(
	id				int(10)		not	null,	/* id 相同的为同一个订单 */
    tripID			int(10)		not	null,	/* Table:tirp Item:id */
    createDate		date		not null,
    createTime		time		not null,
    totalFare		float(6,2)	not	null,
    contactName		varchar(20)	not	null,
    contactPhone 	varchar(20) not null
);

二、系统展示

1.机票查询

在这里插入图片描述

2.选择航班

在这里插入图片描述

3.填写乘客和联系人信息、提交订单

在这里插入图片描述

4.订单详细信息

在这里插入图片描述

三、部分代码

SearchAction


package com.abs.action;

import java.sql.Date;
import java.sql.Time;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.*;

import com.abs.db.DBName;
import com.abs.factory.DaoFactory;
import com.abs.model.*;

public class SearchAction {
	
	public static List<FlightInfo> searchFlightDirectly(String departureCity, String arrivalCity, String departureDateString) throws Exception {
		List<FlightInfo> list = null;
		
		Date departureDate = null;
		if (checkDate(departureDateString)) {	//	测试Date格式是否合格
			departureDate = Date.valueOf(departureDateString);
		}
		
		list = DaoFactory.getFlightInfoDaoInstance(DBName.ABS).findByAirport(departureCity, arrivalCity, departureDate);
		
		return list;
	}
	
	public static List<List<FlightInfo>> searchFlightTransfer(String departureCity, String arrivalCity, String departureDateString) throws Exception {
		List<List<FlightInfo>> list = new ArrayList<List<FlightInfo>>();
		
		Date departureDate = null;
		if (checkDate(departureDateString)) {	//	测试Date格式是否合格
			departureDate = Date.valueOf(departureDateString);
		}
		
		List<FlightInfo> departureList = DaoFactory.getFlightInfoDaoInstance(DBName.ABS).findByDepatureAirport(departureCity, departureDate);
		
		for (FlightInfo depatureFlight : departureList) {
			Airport transferAirport = DaoFactory.getAirportDaoInstance(DBName.ABS).findByCode(depatureFlight.getArrivalAirport());
			
			if(null != transferAirport){
				int connTime = transferAirport.getConnTime();	
				Time depatureTime = new Time(depatureFlight.getArrivalTime().getTime() + connTime * 60 * 1000);
				String transferCity = depatureFlight.getArrivalAirportCity();
				
				List<FlightInfo> arrivalList = DaoFactory.getFlightInfoDaoInstance(DBName.ABS).findByTransferArrivalAirport(transferCity, arrivalCity, departureDate, depatureTime);
				
				for (FlightInfo arrivalFlight : arrivalList) {
					List<FlightInfo> item = new ArrayList<FlightInfo>();
					if(depatureFlight.getAirlineCode().equals(arrivalFlight.<

以上是关于Java实现Web航空订票系统(servlet+jdbc+jsp+mysql)的主要内容,如果未能解决你的问题,请参考以下文章

java毕设---基于servlet+jsp+mysql的航空订票系统

IDEA+Java+Servlet+JSP+Mysql实现Web图书管理系统

基于JAVA的网上机票预订系统的设计与实现(航空订票系统)

基于JSP Servlet3.0 MySQL 的在线影院订票系统-作为程序员入门学习和毕业设计课题设计项目,真香!

Java+Servlet+JSP+Mysql+Tomcat实现Web学生选课管理系统

IDEA+Java+Servlet+JSP+Bootstrap+Mysql实现Web学生宿舍管理系统