国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

JavaWeb項目:航班信息管理系統(tǒng)(tomcat+jsp)

這篇具有很好參考價值的文章主要介紹了JavaWeb項目:航班信息管理系統(tǒng)(tomcat+jsp)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一:項目業(yè)務(wù)需求

航班信息管理系統(tǒng)是學(xué)習(xí)Javaweb的一個小項目,首先對該項目的業(yè)務(wù)需求進(jìn)行分析,根據(jù)項目文檔知它的主要實現(xiàn)技術(shù)為 SERVLET、JSP、MVC 架構(gòu)、JDBC 和 MySQL。該項目著重學(xué)生的實際應(yīng)用場景來設(shè)計,模擬 機(jī)場中的航班系統(tǒng)的業(yè)務(wù)實現(xiàn)以及擴(kuò)展,能夠?qū)崿F(xiàn)航班信息管理的的所有功能,包括航班信息,航 班目的地查詢等功能的實現(xiàn);

本項目共實現(xiàn)八大功能模塊

? 注冊模塊:用戶輸入用戶名,真實姓名,密碼進(jìn)行注冊,注冊驗證通過后,將用戶存儲到數(shù)據(jù)庫中,如果數(shù)據(jù)庫中已有相同用戶名,則需要重新注冊。

登錄模塊:對管理員輸入的用戶名,密碼進(jìn)行驗證,驗證通過后,管理員可以使用航班信息管 理系統(tǒng)中所有權(quán)限的功能,否則重新登錄該系統(tǒng)。

航班信息管理功能:管理員登錄成功,可以查詢所有航班信息。 .

新增航班信息功能:管理員登錄成功,可以新增航班信息,新增完畢以后跳轉(zhuǎn)到主頁面顯示所

以航班信息

刪除航班信息功能:管理員登錄成功,可以刪除航班信息,刪除完畢以后跳轉(zhuǎn)到主頁面顯示所 以航班信息

修改航班信息功能:管理員登錄成功,可以修改航班信息,修改完畢以后跳轉(zhuǎn)到主頁面顯示所 以航班信息

根據(jù)目的地查詢功能:管理員登錄成功,可以根據(jù)目的地對航班信息進(jìn)行查詢。

根據(jù)起飛時間查詢功能:管理員登錄成功,可以根據(jù)起飛時間對航班信息進(jìn)行查詢。

二:項目邏輯實現(xiàn)

?在實現(xiàn)邏輯之前,先看一下項目演示

航班信息管理系統(tǒng)演示

項目演示完畢,我們分模塊進(jìn)行代碼實現(xiàn)

首先,先看一下項目架構(gòu)

后端

javaweb航空管理系統(tǒng),java,tomcat,開發(fā)語言,intellij-idea

后端工程采用mvc架構(gòu),分別是bean(實體類)dao(處理類)service(服務(wù)類)servlet(啟動類),util(工具類)以及一個jdbc連接數(shù)據(jù)庫的測試類。

前端

javaweb航空管理系統(tǒng),java,tomcat,開發(fā)語言,intellij-idea

前端頁面采用jsp頁面和css樣式

其中在WEB-INF文件夾中創(chuàng)建一個lib目錄并引入三個jar包,右鍵lib目錄點擊 add libary

javaweb航空管理系統(tǒng),java,tomcat,開發(fā)語言,intellij-idea

下面,我們開始寫代碼

首先創(chuàng)建實體類

User

package com.ambow.bean;

public class User {
    private int userId;
    private String userName;
    private String password;
    private String realName;

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }
}

Flight

package com.ambow.bean;

import java.util.Date;

public class Flight {
    private int idFlight;  //航班編號
    private int flightId; //航班號
    private String destination;  //目的地
    private Date takeName;  //起飛時間
    public int getIdFlight() {
        return idFlight;
    }

    public void setIdFlight(int idFlight) {
        this.idFlight = idFlight;
    }

    public int getFlightId() {
        return flightId;
    }

    public void setFlightId(int flightId) {
        this.flightId = flightId;
    }

    public String getDestination() {
        return destination;
    }

    public void setDestination(String destination) {
        this.destination = destination;
    }

    public Date getTakeName() {
        return takeName;
    }

    public void setTakeName(Date takeName) {
        this.takeName = takeName;
    }
}

實體類寫完,我們開始寫Dao層,寫Dao層的類需要連接數(shù)據(jù)庫

我們先來測試一下數(shù)據(jù)庫是否能連接成功,輸入以下代碼測試數(shù)據(jù)庫連接是否成功

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class jdbcTest {
    public static void conn(){
        Connection connection;
        String url = "jdbc:mysql://localhost:3306/flightinformationmanagesystem";   //數(shù)據(jù)庫連接的url地址
        String user = "root";   //數(shù)據(jù)庫用戶名
        String password = "123456";  //數(shù)據(jù)庫密碼
        try {
            //加載數(shù)據(jù)庫驅(qū)動
            Class.forName("com.mysql.cj.jdbc.Driver");
            System.out.println("數(shù)據(jù)庫驅(qū)動加載成功!");
        }catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try{
            //通過DriverManager獲取數(shù)據(jù)庫連接
            connection = DriverManager.getConnection(url,user,password);
            System.out.println("數(shù)據(jù)庫連接成功!");
        }catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        jdbcTest.conn();
    }
}

輸出

javaweb航空管理系統(tǒng),java,tomcat,開發(fā)語言,intellij-idea

說明數(shù)據(jù)庫連接成功

下面我們開始寫Dao層代碼

首先,創(chuàng)建一個連接數(shù)據(jù)庫的工具類,將數(shù)據(jù)庫連接封裝到一個工具類中

package com.ambow.util;

import java.sql.*;

/*
封裝數(shù)據(jù)庫
 */
public class DBConnection {
    private static final String username = "root";
    private static final String password = "123456";
    private static final String url = "jdbc:mysql://localhost:3306/flightinformationmanagesystem";
    //加載數(shù)據(jù)庫驅(qū)動
    public static void main(String[] args) {
        try{
            Class.forName("com.mysql.jdbc.Driver");
        }catch (ClassNotFoundException e){
            e.printStackTrace();
        }
    }
    //獲取數(shù)據(jù)庫連接方法
    public static Connection getConnection(){
        Connection connection = null;
        try {
            connection = DriverManager.getConnection(url,username,password);
        }catch (SQLException e){
            e.printStackTrace();
        }
        return connection;
    }
    //數(shù)據(jù)庫釋放三個資源
    public static void closeAll(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet){
        try{
            if (connection != null){
                connection.close();
            }
            if (preparedStatement != null){
                preparedStatement.close();
            }
            if (resultSet != null){
                resultSet.close();
            }
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
    //數(shù)據(jù)庫釋放兩個資源
    public static void closeTwo(Connection connection, PreparedStatement preparedStatement){
        try{
            if (connection != null){
                connection.close();
            }
            if (preparedStatement != null){
                preparedStatement.close();
            }
        }catch (SQLException e){
            e.printStackTrace();
        }

    }
}

當(dāng)連接數(shù)據(jù)庫時,我們調(diào)用工具類進(jìn)行連接

先寫RegisterDao

package com.ambow.dao;

import com.ambow.util.DBConnection;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class RegisterDao {
    //注冊功能
    public boolean register(String username,String password, String realname){

        String sql = "insert into flightinformationmanagesystem.user(loginname, password, realname) values (?,?,?)";
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        try{
            connection = DBConnection.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,username);
            preparedStatement.setString(2,password);
            preparedStatement.setString(3,realname);
            int resultSet = preparedStatement.executeUpdate();
            return resultSet > 0;
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            DBConnection.closeTwo(connection,preparedStatement);
        }
        return false;

    }
}

然后是UserDao

package com.ambow.dao;

import com.ambow.bean.User;
import com.ambow.util.DBConnection;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao {
    //登錄功能
    public User selectByNameAndPassword(String loginname, String password){
        User user = new User();
        String sql = "select * from flightinformationmanagesystem.user where loginname=? and password=?";
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try{
            //獲取數(shù)據(jù)庫連接對象
            connection = DBConnection.getConnection();
            //預(yù)編譯
            preparedStatement = connection.prepareStatement(sql);
            //給參數(shù)賦值
            preparedStatement.setString(1,loginname);
            preparedStatement.setString(2,password);
            resultSet = preparedStatement.executeQuery();
            if (resultSet.next()){
                //創(chuàng)建用戶對象
                user.setUserId(resultSet.getInt(1));  //1代表數(shù)據(jù)庫中的第一列
                user.setUserName(resultSet.getString(2));  //2代表第二列
                user.setPassword(resultSet.getString(3));
                user.setRealName(resultSet.getString(4));
            }
        }catch (SQLException e){
            e.printStackTrace();
        }
        finally {
            DBConnection.closeAll(connection,preparedStatement,resultSet);
        }
        return user;
    }
}

FlightDao

package com.ambow.dao;

import com.ambow.bean.Flight;
import com.ambow.util.DBConnection;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class FlightDao {
    // 查找全部航班信息
    public static List<Flight> selectAll() {
        String sql = "SELECT * FROM flightinformationmanagesystem.flight";
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        List<Flight> flightList = new ArrayList<>();
        try {
            // 獲取數(shù)據(jù)庫連接對象
            conn = DBConnection.getConnection();
            // 預(yù)編譯并執(zhí)行查詢語句
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();

            // 處理查詢結(jié)果
            while (rs.next()) {
                Flight flight = new Flight();
                flight.setIdFlight(rs.getInt(1));
                flight.setFlightId(rs.getInt(2));
                flight.setDestination(rs.getString(3));
                flight.setTakeName(rs.getDate(4));
                flightList.add(flight);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            // 關(guān)閉資源
            DBConnection.closeAll(conn, ps, rs);
        }
        return flightList;
    }

    //按目的地查詢航班信息
    public static List<Flight> selectAllByDestination(Flight flight){
        String sql = "select * from flightinformationmanagesystem.flight where destination=?";
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        List<Flight> flightList = new ArrayList<>();
        try{
            //獲取數(shù)據(jù)庫連接對象
            connection = DBConnection.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, flight.getDestination());
            resultSet = preparedStatement.executeQuery();
            while (resultSet.next()){
                flight.setIdFlight(resultSet.getInt("id"));
                flight.setFlightId(resultSet.getInt("flightid"));
                flight.setDestination(resultSet.getString("destination"));
                flight.setTakeName(resultSet.getDate("taketime"));
                flightList.add(flight); // 將新對象添加到列表
            }


        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            DBConnection.closeAll(connection,preparedStatement,resultSet);
        }
        return flightList;
    }
    //按起飛時間查詢航班信息
    public static List<Flight> selectAllByTaketime(Flight flight){
        String sql = "select * from flightinformationmanagesystem.flight where taketime=?";
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        List<Flight> flightList = new ArrayList<>();
        try{
            //獲取數(shù)據(jù)庫連接對象
            connection = DBConnection.getConnection();
            preparedStatement = connection.prepareStatement(sql);

            preparedStatement.setDate(1, new java.sql.Date(flight.getTakeName().getTime()));
            resultSet = preparedStatement.executeQuery();
            while (resultSet.next()){
                flight.setIdFlight(resultSet.getInt("id"));
                flight.setFlightId(resultSet.getInt("flightid"));
                flight.setDestination(resultSet.getString("destination"));
                flight.setTakeName(resultSet.getDate("taketime"));
                flightList.add(flight); // 將新對象添加到列表
            }


        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            DBConnection.closeAll(connection,preparedStatement,resultSet);
        }
        return flightList;
    }
    //按ID查詢航班信息
    public  Flight selectById(int flightId){
        String sql = "select * from flightinformationmanagesystem.flight where id=?";
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        Flight flight = null;
        try{
            //獲取數(shù)據(jù)庫連接對象
            connection = DBConnection.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setInt(1, flightId);
            resultSet = preparedStatement.executeQuery();
            while (resultSet.next()){
                flight = new Flight();
                flight.setFlightId(resultSet.getInt("flightid"));
                flight.setDestination(resultSet.getString("destination"));
                flight.setTakeName(resultSet.getDate("taketime"));

            }

        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            DBConnection.closeAll(connection,preparedStatement,resultSet);
        }
        return flight;
    }
    //增加航班
    public static int add(Flight flight){
        String sql = "insert into flightinformationmanagesystem.flight(flightid, destination, taketime) values(?,?,?)";
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        int flag = 0;
        try{
            //獲取數(shù)據(jù)庫連接對象
            connection = DBConnection.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setInt(1, flight.getFlightId());
            preparedStatement.setString(2, flight.getDestination());
            preparedStatement.setDate(3,new java.sql.Date(flight.getTakeName().getTime()));
            flag = preparedStatement.executeUpdate();
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            DBConnection.closeTwo(connection,preparedStatement);
        }
        return flag;
    }
    //修改航班
    public static int update(Flight flight){
        String sql = "update flightinformationmanagesystem.flight SET destination=?,taketime=? where flightid=?";
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        int flag = 0;
        try{
            connection = DBConnection.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, flight.getDestination());
            preparedStatement.setDate(2,new java.sql.Date(flight.getTakeName().getTime()));
            preparedStatement.setInt(3, flight.getFlightId());
            flag = preparedStatement.executeUpdate();

        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            DBConnection.closeTwo(connection,preparedStatement);
        }
        return flag;
    }
    //刪除航班
    public static int delete(Flight flight){
        String sql = "delete from flightinformationmanagesystem.flight where id=?";
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        int flag = 0;
        try{
            connection = DBConnection.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setInt(1, flight.getIdFlight());
            flag = preparedStatement.executeUpdate();
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            DBConnection.closeTwo(connection,preparedStatement);
        }
        return flag;
    }
}

下面寫Service層

首先是RegisterService

package com.ambow.service;

import com.ambow.bean.User;
import com.ambow.dao.RegisterDao;
import com.ambow.util.DBConnection;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class RegisterService {
    //判斷用戶是否存在
    public User userIsExist(String username){
        String sql = "select loginname from flightinformationmanagesystem.user where loginname =?";
        User user = null;
        Connection connection = null;
        PreparedStatement preparedStatement =null;
        ResultSet resultSet = null;
        try{
            connection = DBConnection.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,username);
            resultSet = preparedStatement.executeQuery();
            while (resultSet.next()){
                user = new User();
                user.setUserName(resultSet.getString("loginname"));
            }
        }catch (SQLException e){
            e.printStackTrace();
        }
        finally {
            DBConnection.closeAll(connection,preparedStatement,resultSet);
        }
        return user;
    }
    //調(diào)用RegisterDao類
    RegisterDao registerDao = new RegisterDao();
    public Boolean Register(String username,String password,String realname){
        boolean isSuccess = registerDao.register(username,password,realname);
        if (isSuccess){
            return isSuccess;
        }
        return null;
    }

}

UserService

package com.ambow.service;

import com.ambow.bean.User;
import com.ambow.dao.UserDao;
import com.ambow.util.DBConnection;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserService {
    public User userIsExist(String username){
        String sql = "select loginname from flightinformationmanagesystem.user where loginname =?";
        User user = null;
        Connection connection = null;
        PreparedStatement preparedStatement =null;
        ResultSet resultSet = null;
        try{
            connection = DBConnection.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,username);
            preparedStatement.executeQuery();
            while (resultSet.next()){
                user = new User();
                user.setUserName(resultSet.getString("loginname"));
            }
        }catch (SQLException e){
            e.printStackTrace();
        }
        finally {
            DBConnection.closeAll(connection,preparedStatement,resultSet);
        }
        return user;
    }

    //調(diào)用UserDao類
    UserDao userDao = new UserDao();
    //service層的selectByNameAndPassword方法
    public User selectByNameAndPassword(String userName, String Password){
        //調(diào)用UserDao類的selectByNameAndPassword方法
        User isSuccess = userDao.selectByNameAndPassword(userName,Password);
        //如果isSuccess不為空且密碼相等,返回應(yīng)該isSuccess
        if (isSuccess != null && Password.equals(isSuccess.getPassword())){
            return isSuccess;
        }
        return null;
    }
}

FlightService

package com.ambow.service;

import com.ambow.bean.Flight;
import com.ambow.dao.FlightDao;

import java.util.Date;
import java.util.List;

public class FlightService {
    FlightDao flightDao = new FlightDao();
    //查詢所有航班信息
    public List<Flight> selectAll(){
        List<Flight> flightList = FlightDao.selectAll();
        return flightList;
    }
    //通過id查詢航班信息
    public Flight selectById(int flightId){

        Flight flight = flightDao.selectById(flightId);
        return flight;
    }
    //通過目的地查詢航班信息
    public List<Flight> selectByDestination(String destination){
        Flight flight =new Flight();
        flight.setDestination(destination);
        List<Flight> flightList = FlightDao.selectAllByDestination(flight);
        return flightList;
    }
    //通過起飛時間查詢航班信息

    public List<Flight> selectByTaketime(Flight flight){
        List<Flight> flightList = FlightDao.selectAllByTaketime(flight);
        return flightList;
    }

    //增加航班信息
    public boolean add(Flight flight){
        int flag = FlightDao.add(flight);
        if(flag == 1){
            return true;
        }else {
            return false;
        }
    }
    //修改航班信息
    public boolean update(Flight flight){
        int flag = FlightDao.update(flight);
        if(flag == 1){
            return true;
        }else {
            return false;
        }
    }
    //刪除航班信息
    public boolean delete(Flight flight){
        int flag = FlightDao.delete(flight);
        if(flag == 1){
            return true;
        }else {
            return false;
        }
    }
}

?然后是servlet層

servlet層代碼較多,我們慢慢來

RegisterServlet

package com.ambow.servlet;

import com.ambow.bean.User;
import com.ambow.service.RegisterService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "RegisterServlet",urlPatterns = "/RegisterServlet")
public class RegisterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //設(shè)置字符編碼,防止亂碼
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        //獲取表單信息
        String username = request.getParameter("username");
        String realname = request.getParameter("fullname");
        String password = request.getParameter("password");
        //檢查用戶名和密碼是否為空
        if (username == null || username.isEmpty() || password == null || password.isEmpty()) {
          String scr ="<script>alert('用戶名和密碼不能為空!');window.location.href='register.jsp'</script>";
          response.getWriter().write(scr);
        }else{
            //調(diào)用Register類進(jìn)行注冊
            RegisterService registerService = new RegisterService();
            //檢查用戶名是否已經(jīng)存在
            User userIsExist = registerService.userIsExist(username);
            if (userIsExist != null){
               String scrs =  "<script>alert('用戶名已經(jīng)存在,請選擇其他用戶名!');window.location.href='register.jsp'</script>";
               response.getWriter().write(scrs);
            }else {
                //注冊用戶
                Boolean register = registerService.Register(username, password, realname);
                if (register){
                 String scri ="<script>alert('注冊成功!');window.location.href='login.jsp'</script>";
                 response.getWriter().write(scri);
                }else {
                    String scrip ="<script>alert('注冊失敗!');window.location.href='register.jsp'</script>";
                    response.getWriter().write(scrip);
                }
            }
            
        }
    }
}

UerServlet

package com.ambow.servlet;

import com.ambow.bean.User;
import com.ambow.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(name = "LoginServlet",urlPatterns = "/LoginServlet")
public class UserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //設(shè)置中文字符,防止亂碼
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        //提交客戶端信息
        String userName = request.getParameter("username");
        String password = request.getParameter("password");
        // 檢查用戶名和密碼是否為空
        if (userName == null || userName.isEmpty() || password == null || password.isEmpty()){
            String scr ="<script>alert('用戶名或密碼為空!');window.location.href='login.jsp'</script>";
            response.getWriter().write(scr);
        }else {
            //調(diào)用UserService
            UserService userService = new UserService();
            User user = userService.selectByNameAndPassword(userName,password);

            if(user != null){
//                request.setAttribute("user",userName);
//                response.sendRedirect("main.jsp");
                 //設(shè)置登錄成功的標(biāo)志
                request.setAttribute("loginSuccessful", true);
                request.getSession().setAttribute("user", user); // 將用戶存儲到 session 中,以便在后續(xù)請求中使用
                response.sendRedirect(request.getContextPath() + "/FlightServlet"); // 執(zhí)行重定向到 /FlightServlet 路徑
            }else {
               String scr ="<script>alert('用戶名或密碼錯誤,請仔細(xì)檢查后登錄!');window.location.href='login.jsp'</script>";
               response.getWriter().write(scr);
            }
        }


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}

LoginOutServlet

package com.ambow.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet(name = "LogoutServlet", urlPatterns = "/LogoutServlet")
public class LoginOutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        performLogout(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        performLogout(request,response);
    }

    private void performLogout(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();

         //清除 session 中的用戶信息
        session.removeAttribute("user");

//        // 或者直接使整個 session 失效
//         session.invalidate();

        // 重定向到登錄頁面或其他頁面
        response.sendRedirect(request.getContextPath() + "/login.jsp");
    }
}

?AddServlet

package com.ambow.servlet;

import com.ambow.bean.Flight;
import com.ambow.service.FlightService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet(name = "AddFlightServlet",urlPatterns = "/AddFlightServlet")
public class AddFlightServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //設(shè)置編碼格式
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        //獲取客戶端信息
        String flightid = request.getParameter("flightId");
        String destination = request.getParameter("destination");
        String taketime = request.getParameter("takeoffTime");
        //實例化Flight對象并設(shè)置屬性
        Flight flight = new Flight();
        //將字符串類型轉(zhuǎn)換成整形
        flight.setFlightId(Integer.parseInt(flightid));
        flight.setDestination(destination);
        //將字符串類型轉(zhuǎn)換成Date類型
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date taketimes =null;
        try{
             taketimes = simpleDateFormat.parse(taketime);
        }catch (ParseException e){
            e.printStackTrace();
        }
        flight.setTakeName(taketimes);
        //調(diào)用FlightService類
        FlightService flightService = new FlightService();
        boolean isAddSuccess = flightService.add(flight);
        if (isAddSuccess){
            // 重定向到航班信息頁面
            response.sendRedirect(request.getContextPath() + "/FlightServlet");
        }else {
            String scr = "<script>alert('航班信息添加失敗,請重試!');window.location.href='AddFlight.jsp'</script>";
            response.getWriter().write(scr);
        }
//        //獲取返回主頁面按鈕
//        String btn = request.getParameter("back");
//        if ("back".equals(btn)){
//            // 重定向到航班信息頁面
//            response.sendRedirect(request.getContextPath() + "/FlightServlet");
//        }

    }
}

?DeleteServlet

package com.ambow.servlet;

import com.ambow.bean.Flight;
import com.ambow.service.FlightService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(name = "DeleteFlightServlet", urlPatterns = "/DeleteFlightServlet")
public class DeleteFlightServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //獲取要刪除的航班id
        int idFlight = Integer.parseInt(request.getParameter("flightId"));
        //調(diào)用FlightService類中的delete方法進(jìn)行刪除
        FlightService flightService = new FlightService();
        Flight flight = new Flight();
        flight.setIdFlight(idFlight);
        boolean isDeleteSuccess = flightService.delete(flight);
        if (isDeleteSuccess) {
            // 刪除成功,重定向到顯示航班信息的頁面
            response.sendRedirect(request.getContextPath() + "/FlightServlet");
        } else {
            // 刪除失敗,返回錯誤頁面或其他處理
            String scr = "<script>alert('航班信息刪除失敗,請重試!');window.location.href='main.jsp'</script>";
            response.getWriter().write(scr);
        }
    }
}

?EditFlightServlet

package com.ambow.servlet;

import com.ambow.bean.Flight;
import com.ambow.service.FlightService;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet(name = "EditFlightServlet", urlPatterns = "/EditFlightServlet")
public class EditFlightServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //獲取用戶表單信息
        String flightIdParam = request.getParameter("id");
        if (flightIdParam != null && !flightIdParam.isEmpty()) {
            int Idflight = Integer.parseInt(flightIdParam);
            //查詢數(shù)據(jù)庫,獲取航班信息
            FlightService flightService = new FlightService();
            Flight flights =  flightService.selectById(Idflight);
            //將航班信息存儲到 request 屬性中
            request.setAttribute("flights", flights);
            request.getRequestDispatcher("UpdateFlight.jsp").forward(request, response);

        }else {
            response.sendRedirect(request.getContextPath() + "/FlightServlet");
        }
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}

FlightServlet

package com.ambow.servlet;

import com.ambow.bean.Flight;
import com.ambow.bean.User;
import com.ambow.service.FlightService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/FlightServlet")
public class FlightServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        //創(chuàng)建service對象,調(diào)用查詢所有的方法
        FlightService fs = new FlightService();
        //調(diào)用查詢所有的方法
        List<Flight> flights = fs.selectAll();
        //將信息儲存到作用域中
        request.setAttribute("flights",flights);
        //轉(zhuǎn)發(fā)到FlightInfo.jsp頁面
        request.getRequestDispatcher("main.jsp").forward(request, response);

    }
}

?SelectByDestinationServlet

package com.ambow.servlet;

import com.ambow.bean.Flight;
import com.ambow.service.FlightService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "SelectByDestination",urlPatterns = "/SelectByDestination")
public class SelectByDestinationServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //設(shè)置編碼格式
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        // 獲取客戶端信息
        String destination = request.getParameter("destination");

        // 調(diào)用 FlightService 類
        FlightService flightService = new FlightService();
        List<Flight> flights = flightService.selectByDestination(destination);

        if (flights != null && !flights.isEmpty()) {
            // 將信息儲存到作用域中
            request.setAttribute("flights", flights);
            // 轉(zhuǎn)發(fā)到 main.jsp 頁面
            request.getRequestDispatcher("main.jsp").forward(request, response);
        } else {
            // 目的地找不到的處理邏輯
            String scr = "<script>alert('該目的地找不到!');window.location.href='SelectByDestination.jsp'</script>";
            response.getWriter().write(scr);
        }
    }
}

?SelectByTaketimeServlet

package com.ambow.servlet;

import com.ambow.bean.Flight;
import com.ambow.service.FlightService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@WebServlet(name = "SelectByTaketime",urlPatterns = "/SelectByTaketime")
public class SelectByTaketimeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //設(shè)置編碼格式
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        // 獲取客戶端信息
        String taketime = request.getParameter("taketime");
        //實例化Flight對象并設(shè)置屬性
        Flight flight = new Flight();
        //將字符串類型轉(zhuǎn)換成Date類型
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date taketimes =null;
        try{
            taketimes = simpleDateFormat.parse(taketime);
        }catch (ParseException e){
            e.printStackTrace();
        }
        flight.setTakeName(taketimes);

        // 調(diào)用 FlightService 類
        FlightService flightService = new FlightService();
        List<Flight> flights = flightService.selectByTaketime(flight);

        if (flights != null && !flights.isEmpty()) {
            // 將信息儲存到作用域中
            request.setAttribute("flights", flights);
            // 轉(zhuǎn)發(fā)到 main.jsp 頁面
            request.getRequestDispatcher("main.jsp").forward(request, response);
        } else {
            // 目的地找不到的處理邏輯
            String scr = "<script>alert('該起飛時間找不到!');window.location.href='SelectByTaketime.jsp'</script>";
            response.getWriter().write(scr);
        }
    }
}

?UpdateFlightServlet

package com.ambow.servlet;

import com.ambow.bean.Flight;
import com.ambow.service.FlightService;
import com.sun.xml.internal.ws.api.ha.HaInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet(name = "UpdateFlightServlet",urlPatterns = "/UpdateFlightServlet")
public class UpdateFlightServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //設(shè)置編碼格式
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        //獲取客戶端信息
        String flightid = request.getParameter("flightId");
        String destination = request.getParameter("destination");
        String taketime = request.getParameter("takeoffTime");
        //調(diào)用Flight類
        Flight flight = new Flight();
        flight.setFlightId(Integer.parseInt(flightid));
        flight.setDestination(destination);
        //將字符串類型轉(zhuǎn)換成Date類型
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date taketimes =null;
        try{
            taketimes = simpleDateFormat.parse(taketime);
        }catch (ParseException e){
            e.printStackTrace();
        }
        flight.setTakeName(taketimes);
        //調(diào)用FlightService類中的update方法
        FlightService flightService =new FlightService();
        boolean isUpdateSuccess = flightService.update(flight);
        if (isUpdateSuccess){
            // 重定向到航班信息頁面
            response.sendRedirect(request.getContextPath() + "/FlightServlet");
        }else {
            String scr = "<script>alert('航班信息修改失敗,請重試!');window.location.href='UpdateFlight.jsp'</script>";
            response.getWriter().write(scr);
        }

    }
}

三:前端JSP頁面

JSP是原生的HTML頁面添入Java代碼

下面開始編寫JSP代碼

AddFlight.jsp

<%--
  Created by IntelliJ IDEA.
  User: 29988
  Date: 2024/1/4
  Time: 14:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>增加航班信息</title>
  <style type="text/css">
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
      margin: 0;
      display: flex;
    }

    .sidebar {
      background-color: #333;
      color: #fff;
      width: 200px;
      padding: 20px;
      box-sizing: border-box;
    }
    .nav-link {
      text-decoration: none;
      color: #fff;
      font-family: 微軟雅黑, serif;
      display: block;
      padding: 10px;
      margin-bottom: 10px;
      border-radius: 4px;
      transition: background-color 0.3s;
    }

    .nav-link:hover {
      background-color: #555;
    }
    .logout-link {
      margin-top: 20px;
      position: fixed;
      right: 3%;
      top: 3%;
    }
    .loginout{
      text-decoration: none;
      color: #4caf50;
    }
    .user{
      margin-top: 20px;
      position: fixed;
      right: 8%;
      top: 3%;
    }
    .content {
      margin-top: 100px;
      margin-left: 450px;
      padding: 20px;
    }
    .form-container {
      width: 400px;
      margin: 20px;
      padding: 20px;
      box-sizing: border-box;
      background-color: #fff;
      border-radius: 8px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    }
    .form-group {
      margin-bottom: 15px;
    }
    .form-group label {
      display: block;
      font-weight: bold;
      margin-bottom: 5px;
    }
    .form-group input {
      width: 100%;
      padding: 8px;
      box-sizing: border-box;
      border: 1px solid #ccc;
      border-radius: 4px;
    }
    .form-group button {
      background-color: #4caf50;
      color: #fff;
      padding: 10px;
      margin: 10px;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      width: 100%;
    }
    .form-group button:hover {
      background-color: #45a049;
    }
  </style>
</head>
<body>
<div class="sidebar">
  <h2>系統(tǒng)</h2>

  <a class="nav-link" onclick="redirectToMainPage()">主頁</a>
  <a href="SelectByDestination.jsp" class="nav-link">按目的地查詢</a>
  <a href="SelectByTaketime.jsp" class="nav-link">按起飛時間查詢</a>

</div>
<c:if test="${not empty sessionScope.user}">
  <div class="user">
    <p><span>你好, ${sessionScope.user.userName}</span></p>
  </div>
  <div class="logout-link">
    <p><a href="LogoutServlet" class="loginout">注銷</a></p>
  </div>
</c:if>
<c:if test="${empty sessionScope.user}">
  <div>
    <p><a href="login.jsp">登錄</a></p>
  </div>
  <div>
    <p><a href="register.jsp">注冊</a></p>
  </div>
</c:if>

<div class="content">
  <div class="form-container">
    <h2>新增航班信息</h2>
    <form action="AddFlightServlet" method="post">
      <div class="form-group">
        <label for="flightId">航班號:</label>
        <input type="text" id="flightId" name="flightId" required>
      </div>
      <div class="form-group">
        <label for="destination">目的地:</label>
        <input type="text" id="destination" name="destination" required>
      </div>
      <div class="form-group">
        <label for="takeoffTime">起飛時間:</label>
        <input type="date" id="takeoffTime" name="takeoffTime" required>
      </div>
      <div class="form-group">
        <button type="submit">保存</button>
        <button type="button" onclick="redirectToMainPage()">返回主頁面</button>
      </div>
    </form>
  </div>
</div>
<script>
  function redirectToMainPage() {
    window.location.href = "${pageContext.request.contextPath}/FlightServlet";
  }
</script>

</body>
</html>

login.jsp

<%--
  Created by IntelliJ IDEA.
  User: 29988
  Date: 2024/1/2
  Time: 8:42
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<style type="text/css">
  body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
  }

  .login-container {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    width: 400px;
    height:450px;
  }

  .login-container h2 {
    text-align: center;
  }

  .form-group {
    margin-bottom: 15px;
  }

  .form-group label {
    display: block;
    font-weight: bold;
    margin-bottom: 5px;
  }

  .form-group input {
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 4px;
  }

  .form-group button {
    background-color: #4caf50;
    color: #fff;
    padding: 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
  }

  .form-group button:hover {
    background-color: #45a049;
  }
  a{
    text-decoration: none;
    color: #fff;
  }
 .h2s{
   position: fixed;
   top: 7%;
   left: 42%;
   font-family: 幼圓, serif ;
   font-size: 35px;
 }
</style>
  <head>
    <title>登錄</title>
    <link rel="shortcut icon" href="#"/>
  </head>
  <body>

  <h2 class="h2s">航班信息管理系統(tǒng)</h2>
  <div class="login-container">
    <h2>用戶登錄</h2>

    <c:if test="${not empty loginSuccessful}">
      <c:redirect url="/FlightServlet"/>
    </c:if>
    <form action="LoginServlet" method="post">
      <div class="form-group">
        <label for="username">用戶名:</label>
        <input type="text" id="username" name="username" required>
      </div>

      <div class="form-group">
        <label for="password">密碼:</label>
        <input type="password" id="password" name="password" required>
      </div>

      <div class="form-group">
        <button type="submit">登錄</button>
      </div>
      <div class="form-group">
        <button><a href="register.jsp">注冊</a></button>
      </div>
    </form>
  </div>
  </body>
</html>

?main.jsp

<%--
  Created by IntelliJ IDEA.
  User: 29988
  Date: 2024/1/2
  Time: 19:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>航班信息管理系統(tǒng)</title>
    <link rel="shortcut icon" href="#"/>
    <style type="text/css">
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            display: flex;
        }

        .sidebar {
            background-color: #333;
            color: #fff;
            width: 200px;
            padding: 20px;
            box-sizing: border-box;
        }
        .nav-link {
            text-decoration: none;
            color: #fff;
            font-family: 微軟雅黑, serif;
            display: block;
            padding: 10px;
            margin-bottom: 10px;
            border-radius: 4px;
            transition: background-color 0.3s;
        }

        .nav-link:hover {
            background-color: #555;
        }

        .main-content {
            flex: 1;
            padding: 20px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }

        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }

        th {
            background-color: #333;
            color: #fff;
        }

        .logout-link {
            margin-top: 20px;
            position: fixed;
            right: 3%;
            top: 3%;
        }
        .loginout{
            text-decoration: none;
            color: #4caf50;
        }
        .user{
            margin-top: 20px;
            position: fixed;
            right: 8%;
            top: 3%;
        }
        .update{
            text-decoration: none;
            color: black;
        }
    </style>
</head>

<body>
<div class="sidebar">
    <h2>系統(tǒng)</h2>

        <a class="nav-link" onclick="redirectToMainPage()">主頁</a>
        <a href="AddFlight.jsp" class="nav-link">新增</a>
        <a href="SelectByDestination.jsp" class="nav-link">按目的地查詢</a>
        <a href="SelectByTaketime.jsp" class="nav-link">按起飛時間查詢</a>

</div>
<c:if test="${not empty sessionScope.user}">
    <div class="user">
        <p><span>你好, ${sessionScope.user.userName}</span></p>
    </div>
    <div class="logout-link">
        <p><a href="LogoutServlet" class="loginout">注銷</a></p>
    </div>
</c:if>
<c:if test="${empty sessionScope.user}">
    <div>
        <p><a href="login.jsp">登錄</a></p>
    </div>
    <div>
        <p><a href="register.jsp">注冊</a></p>
    </div>
</c:if>

<div class="main-content">
    <h1>航班信息管理系統(tǒng)</h1>
    <table>
        <thead>
        <tr>
            <th>編號</th>
            <th>航班號</th>
            <th>目的地</th>
            <th>起飛時間</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach var="flights" items="${flights}">
        <tr>
            <td>${flights.idFlight}</td>
            <td>${flights.flightId}</td>
            <td>${flights.destination}</td>
            <td>${flights.takeName}</td>
            <td>
                <div style="display: inline-block;">
                        <input type="hidden" name="flightId" value="${flights.idFlight}">
                        <button type="button"><a href="EditFlightServlet?id=${flights.idFlight}" class="update" onclick="return confirm('是否修改?')">修改</a></button>
                </div>
                <div style="display: inline-block;">
                    <form action="DeleteFlightServlet" method="post">
                        <input type="hidden" name="flightId" value="${flights.idFlight}">
                        <button type="submit" onclick="return confirm('是否刪除?')">刪除</button>
                    </form>
            </td>
        </tr>
        </c:forEach>
        </tbody>
    </table>
</div>
<script>
    function redirectToMainPage() {
        window.location.href = "${pageContext.request.contextPath}/FlightServlet";
    }
</script>

</body>
</html>

register.jsp

<%--
  Created by IntelliJ IDEA.
  User: 29988
  Date: 2024/1/2
  Time: 20:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注冊</title>
</head>
<style type="text/css">
    body {
        font-family: Arial, sans-serif;
        background-color: #f4f4f4;
        margin: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100vh;
    }

    .form-container {
        background-color: #fff;
        padding: 20px;
        border-radius: 8px;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        width: 400px;
    }

    .form-container h2 {
        text-align: center;
    }

    .form-group {
        margin-bottom: 15px;
    }

    .form-group label {
        display: block;
        font-weight: bold;
        margin-bottom: 5px;
    }

    .form-group input {
        width: 100%;
        padding: 8px;
        box-sizing: border-box;
        border: 1px solid #ccc;
        border-radius: 4px;
    }

    .form-group button {
        background-color: #4caf50;
        color: #fff;
        padding: 10px;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        width: 100%;
    }

    .form-group button:hover {
        background-color: #45a049;
    }

    .form-group .login-link {
        text-align: center;
        margin-top: 10px;
    }
    .h2s{
        position: fixed;
        top: 7%;
        left: 42%;
        font-family: 幼圓, serif ;
        font-size: 35px;
    }
</style>
<body>
<h2 class="h2s">航班信息管理系統(tǒng)</h2>
<div class="form-container">
    <h2>用戶注冊</h2>
    <form action="RegisterServlet" method="post">
        <div class="form-group">
            <label for="username">用戶名:</label>
            <input type="text" id="username" name="username" required>
        </div>

        <div class="form-group">
            <label for="fullname">真實姓名:</label>
            <input type="text" id="fullname" name="fullname" required>
        </div>

        <div class="form-group">
            <label for="password">密碼:</label>
            <input type="password" id="password" name="password" required>
        </div>

        <div class="form-group">
            <button type="submit">注冊</button>
        </div>

        <div class="form-group login-link">
            <p>已經(jīng)有賬號? <a href="login.jsp">點擊登錄</a></p>
        </div>
    </form>
</div>

</body>
</html>

SelectByDestination.jsp

<%--
  Created by IntelliJ IDEA.
  User: 29988
  Date: 2024/1/5
  Time: 9:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>通過目的地查詢</title>
  <style type="text/css">
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
      margin: 0;
      display: flex;
    }

    .sidebar {
      background-color: #333;
      color: #fff;
      width: 200px;
      padding: 20px;
      box-sizing: border-box;
    }
    .nav-link {
      text-decoration: none;
      color: #fff;
      font-family: 微軟雅黑, serif;
      display: block;
      padding: 10px;
      margin-bottom: 10px;
      border-radius: 4px;
      transition: background-color 0.3s;
    }

    .nav-link:hover {
      background-color: #555;
    }

    .logout-link {
      margin-top: 20px;
      position: fixed;
      right: 3%;
      top: 3%;
    }
    .loginout{
      text-decoration: none;
      color: #4caf50;
    }
    .user{
      margin-top: 20px;
      position: fixed;
      right: 8%;
      top: 3%;
    }
    .form-container {
      background-color: #fff;
      padding: 20px;
      border-radius: 4px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
      text-align: center;
      height: 350px;
      width: 400px;
      margin-left: 450px;
      margin-top: 200px;
    }

    .form-container h2 {
      margin-bottom: 20px;
    }

    .form-container label {
      display: block;
      margin-bottom: 10px;
    }

    .form-container input {
      width: 100%;
      padding: 10px;
      margin-bottom: 20px;
      box-sizing: border-box;
      border: 1px solid #ccc;
      border-radius: 4px;
    }

    .form-container button {
      background-color: #4caf50;
      color: #fff;
      padding: 10px 20px;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      transition: background-color 0.3s;
    }

    .form-container button:hover {
      background-color: #45a049;
    }
  </style>
</head>
<body>
  <div class="sidebar">
    <h2>系統(tǒng)</h2>

    <a class="nav-link" onclick="redirectToMainPage()">主頁</a>
    <a href="AddFlight.jsp" class="nav-link">新增</a>
    <a href="SelectByTaketime.jsp" class="nav-link">按起飛時間查詢</a>

  </div>
  <c:if test="${not empty sessionScope.user}">
    <div class="user">
      <p><span>你好, ${sessionScope.user.userName}</span></p>
    </div>
    <div class="logout-link">
      <p><a href="LogoutServlet" class="loginout">注銷</a></p>
    </div>
  </c:if>
  <div class="form-container">
    <h2>按目的地查詢</h2>
    <form action="SelectByDestination" method="post">
      <label for="destination">目的地:</label>
      <input type="text" id="destination" name="destination" required>
      <br>
      <button type="submit">查詢</button>
    </form>
  </div>
  <script>
    function redirectToMainPage() {
      window.location.href = "${pageContext.request.contextPath}/FlightServlet";
    }
  </script>
</body>
</html>

SelectByTaketime.jsp

<%--
  Created by IntelliJ IDEA.
  User: 29988
  Date: 2024/1/5
  Time: 11:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>通過起飛時間查詢</title>
  <style type="text/css">
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
      margin: 0;
      display: flex;
    }

    .sidebar {
      background-color: #333;
      color: #fff;
      width: 200px;
      padding: 20px;
      box-sizing: border-box;
    }
    .nav-link {
      text-decoration: none;
      color: #fff;
      font-family: 微軟雅黑, serif;
      display: block;
      padding: 10px;
      margin-bottom: 10px;
      border-radius: 4px;
      transition: background-color 0.3s;
    }

    .nav-link:hover {
      background-color: #555;
    }

    .logout-link {
      margin-top: 20px;
      position: fixed;
      right: 3%;
      top: 3%;
    }
    .loginout{
      text-decoration: none;
      color: #4caf50;
    }
    .user{
      margin-top: 20px;
      position: fixed;
      right: 8%;
      top: 3%;
    }
    .form-container {
      background-color: #fff;
      padding: 20px;
      border-radius: 4px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
      text-align: center;
      height: 350px;
      width: 400px;
      margin-left: 450px;
      margin-top: 200px;
    }

    .form-container h2 {
      margin-bottom: 20px;
    }

    .form-container label {
      display: block;
      margin-bottom: 10px;
    }

    .form-container input {
      width: 100%;
      padding: 10px;
      margin-bottom: 20px;
      box-sizing: border-box;
      border: 1px solid #ccc;
      border-radius: 4px;
    }

    .form-container button {
      background-color: #4caf50;
      color: #fff;
      padding: 10px 20px;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      transition: background-color 0.3s;
    }

    .form-container button:hover {
      background-color: #45a049;
    }
  </style>
</head>
<body>
<div class="sidebar">
    <h2>系統(tǒng)</h2>

    <a class="nav-link" onclick="redirectToMainPage()">主頁</a>
    <a href="AddFlight.jsp" class="nav-link">新增</a>
    <a href="SelectByDestination.jsp" class="nav-link">按目的地查詢</a>

  </div>
  <c:if test="${not empty sessionScope.user}">
    <div class="user">
      <p><span>你好, ${sessionScope.user.userName}</span></p>
    </div>
    <div class="logout-link">
      <p><a href="LogoutServlet" class="loginout">注銷</a></p>
    </div>
  </c:if>
<div class="form-container">
  <h2>按起飛時間查詢</h2>
  <form action="SelectByTaketime" method="post">
    <label for="taketime">起飛時間:</label>
    <input type="date" id="taketime" name="taketime" required>
    <br>
    <button type="submit">查詢</button>
  </form>
</div>
<script>
    function redirectToMainPage() {
        window.location.href = "${pageContext.request.contextPath}/FlightServlet";
    }
</script>
</body>
</html>

UpdateFlight.jsp

<%--
  Created by IntelliJ IDEA.
  User: 29988
  Date: 2024/1/4
  Time: 16:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>修改航班信息</title>
  <style type="text/css">
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
      margin: 0;
      display: flex;
    }

    .sidebar {
      background-color: #333;
      color: #fff;
      width: 200px;
      padding: 20px;
      box-sizing: border-box;
    }
    .nav-link {
      text-decoration: none;
      color: #fff;
      font-family: 微軟雅黑, serif;
      display: block;
      padding: 10px;
      margin-bottom: 10px;
      border-radius: 4px;
      transition: background-color 0.3s;
    }
    .nav-link:hover {
      background-color: #555;
    }
    .logout-link {
      margin-top: 20px;
      position: fixed;
      right: 3%;
      top: 3%;
    }
    .loginout{
      text-decoration: none;
      color: #4caf50;
    }
    .user{
      margin-top: 20px;
      position: fixed;
      right: 8%;
      top: 3%;
    }
    .content {
      margin-left: 450px;
      margin-top: 150px;
      background-color: #fff;
      padding: 20px;
      border-radius: 8px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
      width: 350px;
      height: 450px;
      text-align: center;
    }
    form {
      margin-top: 20px;
    }

    label {
      display: block;
      margin-bottom: 8px;
      margin-left: 0;
    }

    input {
      width: 100%;
      padding: 8px;
      margin-bottom: 12px;
      box-sizing: border-box;
      border: 1px solid #ccc;
      border-radius: 4px;
    }

    button {
      background-color: #4caf50;
      color: #fff;
      padding: 10px;
      border: none;
      border-radius: 4px;
      cursor: pointer;
    }

    button:hover {
      background-color: #45a049;
    }
  </style>
</head>
<body>
<div class="sidebar">
  <h2>系統(tǒng)</h2>

  <a class="nav-link" onclick="redirectToMainPage()">主頁</a>
  <a href="AddFlight.jsp" class="nav-link">新增</a>
  <a href="SelectByDestination.jsp" class="nav-link">按目的地查詢</a>
  <a href="SelectByTaketime.jsp" class="nav-link">按起飛時間查詢</a>

</div>
<c:if test="${not empty sessionScope.user}">
  <div class="user">
    <p><span>你好, ${sessionScope.user.userName}</span></p>
  </div>
  <div class="logout-link">
    <p><a href="LogoutServlet" class="loginout">注銷</a></p>
  </div>
</c:if>
<c:if test="${empty sessionScope.user}">
  <div>
    <p><a href="login.jsp">登錄</a></p>
  </div>
  <div>
    <p><a href="register.jsp">注冊</a></p>
  </div>
</c:if>
<div class="content">
  <h2 align="left">編輯航班信息</h2>

    <form action="UpdateFlightServlet" method="post">
      <input type="hidden" name="idFlight" value="${flights.idFlight}">
      <label for="flightId">航班號:</label>
      <input type="text" id="flightId" name="flightId" value="${flights.flightId}" required>
      <br>
      <label for="destination">目的地:</label>
      <input type="text" id="destination" name="destination" value="${flights.destination}" required>
      <br>
      <label for="takeoffTime">起飛時間:</label>
      <input type="text" id="takeoffTime" name="takeoffTime" value="${flights.takeName}" required>
      <br>
      <button type="submit">保存修改</button>
      <button type="button" onclick="redirectToMainPage()">返回主頁面</button>
    </form>

</div>
<script>
  function redirectToMainPage() {
    window.location.href = "${pageContext.request.contextPath}/FlightServlet";
  }
</script>
</body>
</html>

四:SQL語句

根據(jù)大家的需求,sql語句代碼放在下面

本項目一共使用兩個表,一個是user表,用來儲存用戶,一個flight表,用來存儲航班信息

首先是user表

CREATE TABLE `user`  (
  `userid` int NOT NULL AUTO_INCREMENT,
  `loginname` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `password` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `realname` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
  PRIMARY KEY (`userid`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 16 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

然后是flight表

CREATE TABLE `flight`  (
  `id` int NOT NULL AUTO_INCREMENT,
  `flightid` int NOT NULL,
  `destination` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
  `taketime` date NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 27 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

?項目到此基本完成了,如果中間有問題請在評論區(qū)評論!

項目中涉及到的jar包我放在百度網(wǎng)盤了,有需要的大家自行提取
https://pan.baidu.com/s/1LHeAnZ6TsExQCYKEMNqOlg
提取碼:zoyc文章來源地址http://www.zghlxwxcb.cn/news/detail-848784.html

到了這里,關(guān)于JavaWeb項目:航班信息管理系統(tǒng)(tomcat+jsp)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • javaweb權(quán)限管理簡單實現(xiàn)_javaweb管理系統(tǒng)項目

    javaweb權(quán)限管理簡單實現(xiàn)_javaweb管理系統(tǒng)項目

    最近在做一個網(wǎng)站類型項目,主要負(fù)責(zé)后臺,ui框架選型為jquery easy ui,項目架構(gòu)為spring mvc + spring jdbc,簡單易用好上手!搭建好框架后開始了第一個任務(wù),設(shè)計并實現(xiàn)一套簡單的權(quán)限管理功能。 一套最基本的權(quán)限管理包括用戶、角色、資源。 我的設(shè)計如下: 用戶:user 角色

    2024年02月02日
    瀏覽(20)
  • Javaweb學(xué)生信息管理系統(tǒng)(Mysql+JSP+MVC+CSS)

    Javaweb學(xué)生信息管理系統(tǒng)(Mysql+JSP+MVC+CSS)

    項目源碼及數(shù)據(jù)庫: 鏈接:https://pan.baidu.com/s/1ktUyxbOI9lljWr-HRTRIiQ?pwd=1024 提取碼:1024 ? 目錄 一.項目介紹 二.運行效果 1.登錄界面 2.主界面(點擊學(xué)號修改學(xué)生信息) 3.增加學(xué)生界面 ?編輯 三.項目目錄結(jié)構(gòu) ?四.代碼展示 1.jsp及css代碼 ?①登錄界面代碼(login.jsp) ②登錄界面

    2024年02月03日
    瀏覽(21)
  • javaweb項目案例:員工管理系統(tǒng)

    javaweb項目案例:員工管理系統(tǒng)

    使用Javaweb+MySQL實現(xiàn)一個員工管理系統(tǒng),能對員工進(jìn)行增刪改查,使用SSH框架開發(fā)。 manager(管理員表) employee(員工表) systeminfo(系統(tǒng)表) 使用SSH框架開發(fā),使用MySQL數(shù)據(jù)庫。 action:控制器包 dao:數(shù)據(jù)操作接口 dao.Impl:數(shù)據(jù)操作實現(xiàn)工具包 po:實體類包 service:服務(wù)包 ut

    2024年02月11日
    瀏覽(17)
  • 基于javaweb+mysql的jsp+servlet學(xué)生成績管理系統(tǒng)(管理員、教師、學(xué)生)(java+jsp+servlet+javabean+mysql+tomcat)

    基于javaweb+mysql的jsp+servlet學(xué)生成績管理系統(tǒng)(管理員、教師、學(xué)生)(java+jsp+servlet+javabean+mysql+tomcat)

    基于javaweb+mysql的jsp+servlet學(xué)生成績管理系統(tǒng)(管理員、教師、學(xué)生)(java+jsp+servlet+javabean+mysql+tomcat) 運行環(huán)境 Java≥8、MySQL≥5.7、Tomcat≥8 開發(fā)工具 eclipse/idea/myeclipse/sts等均可配置運行 適用 課程設(shè)計,大作業(yè),畢業(yè)設(shè)計,項目練習(xí),學(xué)習(xí)演示等 功能說明 管理員:個人信息、課程

    2024年02月02日
    瀏覽(56)
  • 計算機(jī)畢業(yè)設(shè)計 基于JavaWeb的學(xué)生成績信息管理系統(tǒng)(源碼+論文)

    計算機(jī)畢業(yè)設(shè)計 基于JavaWeb的學(xué)生成績信息管理系統(tǒng)(源碼+論文)

    ?? Hi,各位同學(xué)好呀,這里是L學(xué)長! ??今天向大家分享一個今年(2022)最新完成的畢業(yè)設(shè)計項目作品 基于JavaWeb的學(xué)生成績信息管理系統(tǒng) ?? 學(xué)長根據(jù)實現(xiàn)的難度和等級對項目進(jìn)行評分(最低0分,滿分5分) 難度系數(shù):3分 工作量:3分 創(chuàng)新點:3分 項目獲取: https://gitee.com/sin

    2024年02月10日
    瀏覽(32)
  • javaweb入門版學(xué)生信息管理系統(tǒng)-增刪改查+JSP+Jstl+El

    javaweb入門版學(xué)生信息管理系統(tǒng)-增刪改查+JSP+Jstl+El

    dao ? ?servlet 部分。。。?

    2024年02月10日
    瀏覽(17)
  • 航班進(jìn)出港|航班進(jìn)出港管理系統(tǒng)|基于springboot航班進(jìn)出港管理系統(tǒng)設(shè)計與實現(xiàn)(源碼+數(shù)據(jù)庫+文檔)

    航班進(jìn)出港|航班進(jìn)出港管理系統(tǒng)|基于springboot航班進(jìn)出港管理系統(tǒng)設(shè)計與實現(xiàn)(源碼+數(shù)據(jù)庫+文檔)

    航班進(jìn)出港管理系統(tǒng)目錄 目錄 基于springboot航班進(jìn)出港管理系統(tǒng)設(shè)計與實現(xiàn) 一、前言 二、系統(tǒng)功能設(shè)計 三、系統(tǒng)實現(xiàn) 5、航班信息管理 (1) 航班信息管理 (2)起飛降落申請管理? (3)公告管理 (4)公告類型管理 2、用戶功能實現(xiàn) (1)航班信息 (2)起飛降落申請 (3)

    2024年02月21日
    瀏覽(18)
  • JavaWeb期末項目 圖書館管理系統(tǒng)

    JavaWeb期末項目 圖書館管理系統(tǒng)

    1 項目基本信息 1.1 項目名稱 圖書館管理系統(tǒng) 1.2 開發(fā)運行環(huán)境 Window 10 64位 JDK 1.8.0 Eclipse 4.8版本 MySql 5.5 Tomcat 9.0 2 項目需求分析 2.1 學(xué)生登錄部分 (1)學(xué)生注冊:在進(jìn)入圖書館前必須要登錄,如果沒有學(xué)號則要注冊,注冊時系統(tǒng)會將用戶填寫的學(xué)號與數(shù)據(jù)庫里面的數(shù)據(jù)對比,

    2024年02月10日
    瀏覽(31)
  • Javaweb項目案例:一個簡單的用戶管理系統(tǒng)實現(xiàn)

    Javaweb項目案例:一個簡單的用戶管理系統(tǒng)實現(xiàn)

    我們來設(shè)計一個簡單的用戶管理系統(tǒng),具有查看用戶,添加用戶,刪除用戶,更新用戶的所有功能,并能支持分頁顯示,以及通過模糊查詢的 本項目采用Druid數(shù)據(jù)庫連接池 注意:JDBC和DAO部分本文不予演示,請自行完成此部分代碼的編寫??? 模板頁面,showuser.html Sho

    2024年02月09日
    瀏覽(25)
  • 航班管理系統(tǒng)(最全最細(xì))

    航班管理系統(tǒng)(最全最細(xì))

    ? 【功能需求】 程序啟動后顯示主菜單,包括下面的選項: 1. 顯示航班列表 2. 增加航班 3. 刪除航班 4. 航班訂票 5. 航班退票 6. 航班乘客顯示 7. 航班存盤 8. 從文件調(diào)入航班信息 9. 退出 ??按下相應(yīng)的數(shù)字鍵后進(jìn)入各自的子功能,每個子功能執(zhí)行完畢后,返回并 ??顯示主菜單 【

    2024年02月08日
    瀏覽(37)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包