ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

JSP课程设计——民航售票管理系统

2022-02-02 15:33:36  阅读:188  来源: 互联网

标签:售票 课程设计 rs color height JSP user font border


【超级超级超级超级肝的课设,发出来留个念~】

之前学数据库的时候用java简单实现了民航售票管理端以及客户端的一些功能,这次课程设计算是对上次课设的补充和完善吧,废话不多说了直接上图(有一些小小简陋,轻喷啊!)

一.主页

emmm其实俺也编不出来那么“精致”的界面,好多都是Ctrl+c啦。logo是俺们参加挑战杯设计的,正好能拿过来用,反正就是怎么省事怎么来。

简陋的登录界面——一开始以为挺好弄的,没想到就这一个小熊玩意儿弄了两整天才调好,又是div又是servlet又是Javabean什么什么的,代码在下面哈↓(ps:这是个固定div,有想拿走的可以自己写一下相应div属性)

1.表单

<div class="signform" id="signform" style="display: none">
                  <div class="signclose">
                      <img src="images/cuohao.png" width="35px" height="35px" onclick="signclose()">
                  </div>
                  <form action="loginServlet" method="post">
                  <div class="userdiv">
                      <input id="user" class="signinput" type="text" placeholder="手机号" name="cp" >
                  </div>
                  <div class="pwddiv">
                      <input id="pwd" class="signinput" type="password" placeholder="密码" name="cpassword">
                  </div>

                      <div class="yzmdiv">
                          <br>
                          <input id="yzm" class="" type="text" placeholder="验证码" name="code">
                          <img border=0 src="validate.jsp">
                      </div>

                  <div class="postdiv">
                      <button>登录</button>
                  </div>
                  </form>
                  <br>
                  <div class="change" style="color: #4d4d4d">
                      <p>还没有账号?赶快<a href="register.jsp" style="text-decoration: none;color: #43A047">注册</a>一个吧</p>
                  </div>
              </div>

2.css属性包(好多是无关项,俺没摘出来)

#displaysign{
    position: relative;
    top: 80px;
    width: 70px;
    height: 40px;
}
.signform {
    font-family: 微软雅黑;
    position: fixed;
    background-color: white;
    top: 20%;
    left: 30%;
    width: 500px;
    height: 400px;
    border-radius: 1em;
    text-align: center;
    z-index: 999;
}
#registerform {
    height: 450px;
}
.signclose {
    cursor: pointer;
    float: right;
    overflow: hidden;
    text-align: center;
    position: relative;
    height: 35px;
    width: 35px;
    margin-top: 10px;
    margin-right: 10px;
}
#registerloading{
    position: absolute;
    width: 25px;
    height: 25px;
    left: 410px;
    top: 90px;
}
.signinput {
    text-align: center;
    border-radius: 0.2em;
    width: 280px;
    height: 45px;
    border: none;
    background-color:#f2f2f2;
    font-size: 28px;
}
.signinput::-webkit-input-placeholder {
    font-size: 26px;
}
.userdiv {
    position: relative;
    margin-top: 80px;
}
.pwddiv {
    position: relative;
    margin-top: 20px;
}
.yzmdiv {
    position: relative;
    margin-top: 10px;
}
.postdiv {
    position: relative;
    margin-top: 20px;
}
.postdiv button {
    cursor: pointer;
    color: white;
    font-size: 26px;
    border: none;
    border-radius: 0.4em;
    width: 280px;
    height: 45px;
    background-color:#4CAF50;
}
.yyy {
    position: relative;
    margin-top: 20px;
}

#yyy {
    position: relative;
    margin-top: 20px;
}
#airbu {
    cursor: pointer;
    color: white;
    font-size: 26px;
    border: none;
    border-radius: 0.4em;
    width: 100px;
    height: 45px;
    background-color:#2e6da4;
}
#anum {
    position: relative;
    margin-top: 40px;
}
#airbua {
    cursor: pointer;
    color: white;
    font-size: 26px;
    border: none;
    border-radius: 0.4em;
    width: 200px;
    height: 45px;
    background-color:#2e6da4;
}
#airbub {
    cursor: pointer;
    color: white;
    font-size: 26px;
    border: none;
    border-radius: 0.4em;
    width: 320px;
    height: 45px;
    background-color:#ac2925;
}
#airbuc {
    cursor: pointer;
    color: white;
    font-size: 26px;
    border: none;
    border-radius: 0.4em;
    width: 170px;
    height: 45px;
    background-color:#67b168;
}
#airbud {
    cursor: pointer;
    color: white;
    font-size: 26px;
    border: none;
    border-radius: 0.4em;
    width: 480px;
    height: 45px;
    background-color:#d58512;
}

#airbue {
    cursor: pointer;
    color: white;
    font-size: 26px;
    border: none;
    border-radius: 0.4em;
    width: 180px;
    height: 45px;
    background-color:#4e4f51;
}

.airfont {
    font-family: 微软雅黑;
    color: #4e4f51;
    size: 4px;
    font-weight: bold;
}
.aircheck {
    font-family: 微软雅黑;
    color: orangered;
    size: 4px;
    font-weight: bold;
}


.checklist{
    color: #222222;
    font-weight: bold;
    font-family: 微软雅黑;
}

 3.登录servlet(LoginServlet.java)

package com.test.servlet;
import java.sql.*;
import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

import com.test.jdbc.SqlSrvDBConn;
import com.test.model.vo.UserTable;

public class LoginServlet extends HttpServlet{
    public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
      request.setCharacterEncoding("gb2312");	//设置请求编码
      String cp=request.getParameter("cp");//获取提交的用户名
      String cpassword=request.getParameter("cpassword");//获取提交的密码
      boolean validated=false; //验证成功标识
      SqlSrvDBConn sqlsrvdb=new SqlSrvDBConn();
      HttpSession session=request.getSession();//获得会话对象,用来保存当前登录用户的信息
      UserTable user=null; //先获得UserTable对象,如果是第一次访问该页,用户对象肯定为空,但如果是第二次甚至是第三次,就直接登录主页而无须再次重复验证该用户的信息
      user=(UserTable)session.getAttribute("user");
      //如果用户是第一次进入,会话中尚未存储user持久化对象,故为null
      if(user==null){
    	//查询userTable表中的记录
    	String sql="select * from userTable";
    	ResultSet rs=sqlsrvdb.executeQuery(sql); //取得结果集
        try{
	  while(rs.next()){
	    if((rs.getString("cp").trim().compareTo(cp)==0)&&(rs.getString("cpassword").compareTo(cpassword)==0)){
	      user=new UserTable(); //创建持久化的JavaBean对象user
	      user.setCname(rs.getString(1));
	      user.setCsex(rs.getString(2));
	      user.setCid(rs.getString(3));
	      user.setCaddress(rs.getString(4));
	      user.setCvip(rs.getString(5));
	      user.setCp(rs.getString(6));
	      user.setCpassword(rs.getString(7));
	      session.setAttribute("user",user);//把user对象存储在会话中
	      validated=true;	//标识为true表示验证成功通过
	    }
	  }
	  rs.close();
        }catch(SQLException e){
	  e.printStackTrace();
	}
    	sqlsrvdb.closeStmt();
    	sqlsrvdb.closeConn();
      }else{
        validated=true;	//该用户在之前已登录过并成功验证,故标识为true表示无须再验了
      }

        String code=request.getParameter("code");
        //获取session中的验证码
        String randStr=(String)session.getAttribute("randStr");
        response.setCharacterEncoding("gb2312");
        PrintWriter out=response.getWriter();

      if(validated && code.equals(randStr)){   //验证成功跳转到main.jsp
        response.sendRedirect("index2.jsp");
      }else{  //验证失败跳转到error.jsp
       	response.sendRedirect("error.jsp");
      }
    }
	
    public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
      doGet(request,response);

    }
}


4.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
        <servlet>
            <servlet-name>LoginServlet</servlet-name>
            <servlet-class>com.test.servlet.LoginServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>LoginServlet</servlet-name>
            <url-pattern>/loginServlet</url-pattern>
        </servlet-mapping>
</web-app>

 5.验证码(validate.jsp)

<%@page language="java" import="java.awt.*,java.awt.image.BufferedImage,java.util.*,javax.imageio.ImageIO" pageEncoding="gb2312"%>
<%
  response.setHeader("Cache-Control","no-cache");
  // 在内存中创建图象 
  int width=60,height=20;
  BufferedImage image=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
  //获取画笔
  Graphics g=image.getGraphics();
  //设定背景色 
  g.setColor(new Color(200,200,200));
  g.fillRect(0,0,width,height);
  //取随机产生的验证码(4位数字) 
  Random rnd=new Random();
  int randNum=rnd.nextInt(9000)+1000;
  String randStr=String.valueOf(randNum);
  //将验证码存入session
  session.setAttribute("randStr",randStr);
  //将验证码显示到图象中 
  g.setColor(Color.black);
  g.setFont(new Font("",Font.PLAIN,20));
  g.drawString(randStr,10,17);
  //随机产生100个干扰点,使图象中的验证码不易被其他程序探测到 
  for(int i=0;i<100;i++){
    int x=rnd.nextInt(width);
    int y=rnd.nextInt(height);
    g.drawOval(x,y,1,1);
  }
  //输出图象到页面 
  ImageIO.write(image,"JPEG",response.getOutputStream());
  out.clear();
  out=pageContext.pushBody();
%>

二. 功能界面

1.ER图以及流程图

 

 

 

 

 2.功能简介

(1)客户端:

客户可以通过登录该系统进行航班的查询,其查询方式分为“按日期查询”、“按起始地与目的地查询”、“按日期,起始地与目的地查询”以及“查询所有航班”四种,用户可以通过各种查询渠道得到符合条件的航班信息,并且能根据自己的需求进行购票。在购票界面,用户可以自行挑选客机座位号,并存入自己的订单里。在购票操作中,普通用户原价购买商品,而vip客户可享受8折优惠,另外非会员客户也能办理vip项目。

每个客户有自己的风航空间,在各自的空间里可以更改用户名、密码等信息。

(2)管理端:

管理员可以通过登录管理系统进行机票的查询,其查询方式分为“按日期查询”、“按起始地与目的地查询”、“按日期,起始地与目的地查询”以及“查询所有航班”四种,管理员可以通过各种渠道得到符合条件的机票信息,并且能根据需求进行机票的增删改操作等等。

3.界面展示

 

 

(整套流程如下)


 

 

 

 4.机票信息显示界面代码(仅关键部分代码)

 <% request.setCharacterEncoding("utf-8");
                    if(session.getAttribute("ad")==null) {
                        String ayear = request.getParameter("year");
                        String amonth = request.getParameter("month");
                        String aday = request.getParameter("day");
                        String ad = ayear + amonth + aday;
                        session.setAttribute("ad", ad);
                        out.print(ayear + "年" + amonth + "月" + aday + "日的航班");
                    }
                        String ad1 = (String) session.getAttribute("ad");

                    %>
                    <table border="1" width="700" bgcolor="#b0e0e6"  align="center">
                        <tr><th>序号</th><th>航班号</th><th>logo</th>
                            <th>航空公司</th><th>始发地</th><th>目的地</th><th>起飞时间</th>
                            <th>余票</th><th>。。。</th>
                        </tr>
                        <%



                            String url="jdbc:sqlserver://localhost:1433;databaseName=fenghang";
                            String sqluser="sa";
                            String password="123456";
                            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                            Connection conn=DriverManager.getConnection(url,sqluser,password);

                            int pageSize;   //一页显示的记录数
                            int totalSize;   //记录总数
                            int totalPage;  //总页数
                            int currentPage;       //待显示页码
                            String strPage;
                            int i,id;
                            pageSize=10; //设置一页显示的记录数
                            strPage=request.getParameter("page"); //取得待显示页码
                            if(strPage==null){
                                currentPage=1;
                            }else{
                                currentPage=Integer.parseInt(strPage); //将字符串转换成整型
                            }
                            Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                                    ResultSet.CONCUR_READ_ONLY);
                            String  sql="select * from 航班表 where ad='"+ ad1 +"'";
                            ResultSet  rs=stmt.executeQuery(sql);
                            rs.last(); //光标指向查询结果集中最后一条记录
                            totalSize=rs.getRow(); //获取记录总数
                            totalPage=(totalSize+pageSize-1)/pageSize; //记算总页数

                            if(totalPage>0){
                                rs.absolute((currentPage-1)*pageSize+1);//将记录指针定位到待显示页的第一条记录上
                                i=0;
                                id=(currentPage-1)*pageSize+1;
                                String cNum;
                                while(i<pageSize && !rs.isAfterLast()){
                                    cNum=rs.getString("anum");
                        %>
                        <tr>
                            <td align="center"><a class="airfont"><%=id%></a></td>
                            <td align="center"><a class="airfont"><%=cNum%></a></td>
                            <td align="center"><img src="../images/air/<%=rs.getString("acom")%>.jpg" width="50px" height="50px"></td>
                            <td align="center"><a class="airfont"><%=rs.getString("acom")%></a></td>
                            <td align="center"><a class="airfont"><%=rs.getString("asta")%></a></td>
                            <td align="center"><a class="airfont"><%=rs.getString("ades")%></a></td>
                            <td align="center"><a class="airfont"><%=rs.getString("ad")%></a></td>
                            <td align="center"><a class="airfont"><%=rs.getString("are")%></a></td>
                            <td align="center"><a class="aircheck" href="<% String ppare=rs.getString("are");
                                if (ppare.equals("0"))
                    out.print("../air/nt.jsp");
                            else
                                out.print("../check/ccc.jsp?anum="+cNum);%>">查看</a></td>
                        </tr>
                        <%
                                    rs.next();
                                    i++;id++;
                                }
                            }
                        %>
                    </table>
                    <br>
                    <div align="center">
                        <a style="font-size: x-large;color: slateblue">第<%=currentPage%>页 ,共<%=totalPage%>页</a>
                        <%
                            if(currentPage>1){
                        %>
                        <button id="airbu"><a href="danum1.jsp?page=1&ad=<%=ad1%>" style="color: ghostwhite">第一页</a></button>
                        <button id="airbu"><a href="danum1.jsp?page=<%=currentPage-1%>&ad=<%=ad1%>" style="color: ghostwhite">上一页</a></button>
                        <%
                            }
                            if(currentPage<totalPage){
                        %>
                        <button id="airbu"><a href="danum1.jsp?page=<%=currentPage+1%>&ad=<%=ad1%>" style="color: ghostwhite">下一页</a></button>
                        <button id="airbu"><a href="danum1.jsp?page=<%=totalPage%>&ad=<%=ad1%>" style="color: ghostwhite">尾页</a></button>
                        <%
                            }
                            rs.close();
                            stmt.close();
                            conn.close();
                        %>

 三.参考文献

[1] 耿祥义等.Java2实用教程(第五版)[M].北京:清华大学出版社,2017

[2] 耿祥义等.JSP实用教程(第4版)[M].北京:清华大学出版社,2021

[3] 储久良等.Web前端开发技术——HTML、CSS、JavaScript(第2版)[M].北京:清华大学出版社,2017

[4] 云婷.价值链视角下在线票务服务企业O2O盈利模式研究——以携程网为例 [D].呼和浩特:内蒙古农业大学,2021:6.

四.系统说明

1.本系统需搭载jdk1.8与Tomcat9.0服务器进行运行

2.本系统的最好通过IntelliJ IDEA进行编译及运行,也可通过eclipse运行,但需要修改相关文件(web文件夹重命名为webContent文件夹等等)。

3.本系统src文件夹里存放相关java文件,web文件夹里存放视图相关文件。

4.大致文件结构:

①air目录:客户查询航班类文件

②check目录:购票类文件

③css目录:相关css文件

④customer目录:用户空间及订单类文件

⑤images目录:图片文件

⑥js目录:相关js文件

⑦manager:管理员操作类文件

⑧index.jsp:系统主页

5.数据库要使用Microsoft SQL Server,并将相关文件导入数据库。

五.搞一波小外宣啦!

这是俺的b站嗷,三连三连懂~

<iframe allowfullscreen="true" data-mediaembed="bilibili" id="RcSAbT2B-1643786076176" src="https://player.bilibili.com/player.html?aid=330772544"></iframe>

18,19

六.再有什么问题留言问就好啦,也希望得到各路大佬的指点!

标签:售票,课程设计,rs,color,height,JSP,user,font,border
来源: https://blog.csdn.net/Ice0118360/article/details/122769395

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有