基于javaweb+mysql的jsp+servlet火车票网上订票系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat)

基于javaweb+mysql的jsp+servlet火车票网上订票系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat)

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

管理员

admin 123456

用户

1000001 123456

1000002 123456

1000003 123456

前台功能:用户查询车票信息、登录注册、购票、查看已购车票、修改密码等功能。

后台功能:管理员管理、用户管理、火车信息管理、站点信息管理、线路信息管理、车票信息管理、购票信息管理等。

后台:

前台

技术框架

JSP Servlet MySQL JDBC Tomcat CSS JavaScript

基于javaweb+mysql的JSP+Servlet火车票网上订票系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat)


public class GetZdByTid extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public GetZdByTid() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
			}else{
				bl=db.insort("insert into traininfo(tname,cz,znums,xcnums,traintype) values('"+tnames+"','"+cz+"',"+znums+","+xcnums+",'"+traintype+"')");
				if(!bl){
					json.put("msg", "添加成功。");
				}else{
					json.put("msg", "添加失败");
				}
			}
		}
		//站点信息添加
		if("zhandian".equals(tname)){
			String zdname=request.getParameter("zdname");
			boolean bl=db.checkTrue("select id from zhandian where zdname='"+zdname+"'");
			if(bl){
				json.put("msg", "站点名称已存在");
			}else{
				bl=db.insort("insert into zhandian(zdname) values('"+zdname+"')");
				if(!bl){
					json.put("msg", "添加成功。");
				}else{
					json.put("msg", "添加失败");
				}
			}
		}
		//线路信息添加
		if("xianlu".equals(tname)){
			String tid=request.getParameter("tid");
			String zdid=request.getParameter("zdid");
			String xh=request.getParameter("xh");
			DbConn db2=new DbConn();
			if(db.checkTrue("select id from xianlu where tid="+tid+"  and zdid="+zdid)){
				json.put("msg", "该线路已有该站点");
			}else if(db2.checkTrue("select id from xianlu where tid="+tid+" and xh="+xh)){
				json.put("msg", "站点序号已存在");
			}else{
				boolean bl=db.insort("insert into xianlu(xh,tid,zdid) values("+xh+","+tid+","+zdid+")");
				if(!bl){
					json.put("msg", "添加成功。");
				}else{
					json.put("msg", "添加失败");
				}
			}
		}
		//车票信息添加
		//data:{tname:'piao',"szdid":szdid,"stime":stime,"ezdid":ezdid,"pval":pval,"ptype":ptype,
		//"cxzh":cxzh,"yxsj":yxsj,"tid":tid,idi:ids},
		if("piao".equals(tname)){
			String tid=request.getParameter("tid");
			String szdid=request.getParameter("szdid");
			String ezdid=request.getParameter("ezdid");
			String stime=request.getParameter("stime");
			String pval=request.getParameter("pval");
			String ptype=request.getParameter("ptype");
			}
		}
		//顾客信息删除
		if("cusinfo".equals(tname)){
			String ids=request.getParameter("idi");
			Object cidcard=db.getOnlyOne("select cidcard from cusinfo where id="+ids);
			int bls=db.deleteOrUpdate("delete from cusinfo where id="+ids);
			if(bls>0){
				json.put("msg", 1);
				//顾客信息删除,同时情况,其购票信息
				db.deleteOrUpdate("delete from dpiao where cidcard="+cidcard);
			}else{
				json.put("msg", "删除失败");
			}
		}
		//火车信息删除
		if("traininfo".equals(tname)){
			String ids=request.getParameter("idi");
			if(db.checkTrue("select id from piao where tid="+ids)){
				json.put("msg", "该列车有票务信息存在不能删除.");
			}else if(db.checkTrue("select id from xianlu where tid="+ids)){
				json.put("msg", "该火车有线路信息存在不能删除.");
			}else{
				int bls=db.deleteOrUpdate("delete from traininfo where id="+ids);
				if(bls>0){
					json.put("msg", 1);
				}else{
					json.put("msg", "删除失败");
				}
			}
		}
		//站点信息删除
		if("zhandian".equals(tname)){
			String ids=request.getParameter("idi");
			if(db.checkTrue("select id from xianlu where zdid="+ids)){
				json.put("msg", "该站点有线路信息存在不能删除.");
			}else{
				int bls=db.deleteOrUpdate("delete from zhandian where id="+ids);
				if(bls>0){
					json.put("msg", 1);
				json.put("msg", "删除成功。");
			}else{
				json.put("dt", 0);
				json.put("msg", "tperror:01");
			}
		}else{
			json.put("dt", 0);
		}
		PrintWriter out = response.getWriter();
		out.print(json.toString());
		out.flush();
		out.close();
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html");
		//设置传输数据编码方式
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		//获取前台传送的变量,账号,密码和用户类型
		String uname=request.getParameter("uname");
		String upassword=request.getParameter("upassword");
		String utype=request.getParameter("utype");
		//创建数据库操作对象
		DbConn db=new DbConn();
		//sql语句变量定义
		String sql="";
		int id=-1;
		String usname="";
		if("gly".equals(utype)){
			sql="select id from userinfo where uname='"+uname+"' and upassword='"+upassword+"'";
		}else if("cus".equals(utype)){
			sql="select id,cname from cusinfo where cidcard='"+uname+"' and cpassword='"+upassword+"'";
		}
		JSONObject json=new JSONObject();
		if("".equals(sql)){
			json.put("msg", "系统错误01.");
		}else{
			ResultSet rs=db.query(sql);
			if(rs==null){
				json.put("msg", "系统错误02");
			}else{
				try {
					while(rs.next()){
						id=rs.getInt("id");
						if("cus".equals(utype)){
							usname=rs.getString("cname");
						}else if("gly".equals(utype)){
							usname=uname;
						}
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
}

public class CkSvlt extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public CkSvlt() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred

public class HandlePiaoSvlt extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public HandlePiaoSvlt() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		String id=request.getParameter("idi");
		String flgs=request.getParameter("flgs");
		JSONObject json=new JSONObject();
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		HttpSession session=request.getSession();
		Object userid =session.getAttribute("userid");
		JSONObject json=new JSONObject();
		if(userid==null){
			json.put("msg", "请登录.");
		}else{
			String pid=request.getParameter("pid");
			if("".equals(pid)||pid==null){
				json.put("msg", "error:01");
			}else {
				DbConn db=new DbConn();
				Object cidcard=db.getOnlyOne("select cidcard from cusinfo where id="+userid);
				boolean bl=db.insort("insert into dpiao(cidcard,pid,lyflag) values('"+cidcard+"',"+pid+",'待付款')");
				if(!bl){
					json.put("msg", 1);
				}else{
					json.put("msg", "error:02");
				}
			}
		}
		PrintWriter out = response.getWriter();
		out.print(json.toString());
		out.flush();
		out.close();
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		String tid=request.getParameter("tid");
		JSONObject json=new JSONObject();
		if(!"".equals(tid)&&tid!=null){
			DbConn db=new DbConn();
			ResultSet rs=db.query("select zhandian.* from xianlu,zhandian where xianlu.zdid=zhandian.id and xianlu.tid="+tid);
			List<Zhandian> zdlist=FindService.getZhandian(rs);
			json.put("msg", 1);
			json.put("zdlist", zdlist);
		}else{
			json.put("msg", 0);
		}
		PrintWriter out=response.getWriter();
		out.print(json.toString());
		out.flush();
		out.close();
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//设置传输数据编码方式
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		HttpSession session=request.getSession();
		Object userid=session.getAttribute("userid");
		if(userid==null){
			request.getRequestDispatcher("/CusCkSvlt").forward(request, response);
			return;
		}else{
			DbConn db=new DbConn();
			ResultSet rs=db.query("select dpiao.*,cxzh,ezdid,ezdname,ptype,pval,stime,szdid,szdname,tid,tname,traintype,yxsj from(select tmp.*,zdname as ezdname from(select piao.*,zdname as szdname,tname,traintype  from piao,zhandian,traininfo where piao.tid=traininfo.id and piao.szdid=zhandian.id)tmp,zhandian where tmp.ezdid=zhandian.id)tm,dpiao,cusinfo where tm.id=dpiao.pid and dpiao.cidcard=cusinfo.cidcard and cusinfo.id="+userid);
			List<Dpiao> dplist=FindService.getDpiao(rs);
			request.setAttribute("alist", dplist);
			request.getRequestDispatcher("/customer/main.jsp").forward(request, response);
		}
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//设置传输数据编码方式
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		HttpSession session=request.getSession();
		//获取当前登录用户信息
		Object utype=session.getAttribute("utype");
		Object userid=session.getAttribute("userid");
		//创建json对象
		JSONObject json=new JSONObject();
		if(utype==null||userid==null){
			json.put("msg", "请重新登陆。");
			return;
		}
		//获取前台数据tname
		String tname=request.getParameter("tname");
		//创建数据库操作对象
		DbConn db=new DbConn();
		//管理员信息删除
		if("admin".equals(tname)){
			String ids=request.getParameter("idi");
			ResultSet rs=db.query(sql);
			if(rs==null){
				json.put("msg", "系统错误02");
			}else{
				try {
					while(rs.next()){
						id=rs.getInt("id");
						if("cus".equals(utype)){
							usname=rs.getString("cname");
						}else if("gly".equals(utype)){
							usname=uname;
						}
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(id!=-1){
				HttpSession session=request.getSession();
				json.put("msg", 1);
				session.setAttribute("username", usname);
				session.setAttribute("userid", id);
				session.setAttribute("utype", utype);
			}else{
				json.put("msg", "账号或密码错误。");
			}
		}
			PrintWriter out=response.getWriter();
			out.print(json.toString());
			out.flush();
			out.close();
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

public class Add extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public Add() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
			}else{
				int bls=db.deleteOrUpdate("delete from traininfo where id="+ids);
				if(bls>0){
					json.put("msg", 1);
				}else{
					json.put("msg", "删除失败");
				}
			}
		}
		//站点信息删除
		if("zhandian".equals(tname)){
			String ids=request.getParameter("idi");
			if(db.checkTrue("select id from xianlu where zdid="+ids)){
				json.put("msg", "该站点有线路信息存在不能删除.");
			}else{
				int bls=db.deleteOrUpdate("delete from zhandian where id="+ids);
				if(bls>0){
					json.put("msg", 1);
				}else{
					json.put("msg", "删除失败");
				}
			}
		}
		//线路信息删除
		if("xianlu".equals(tname)){
			String zdid=request.getParameter("zdid");
			String tid=request.getParameter("tid");
			int bls=db.deleteOrUpdate("delete from xianlu where zdid="+zdid+" and tid="+tid);
			if(bls>0){
				json.put("msg", 1);
			}else{
				json.put("msg", "删除失败");
			}
		}
		//车票信息删除
		if("piao".equals(tname)){
			String id=request.getParameter("idi");
			int bls=db.deleteOrUpdate("delete from piao where id="+id);
			if(bls>0){
				json.put("msg", 1);
			}else{
				json.put("msg", "删除失败");
			}
		}
		PrintWriter out=response.getWriter();
		out.print(json.toString());
		out.flush();
		out.close();
	}

	/**

public class DpListSvlt extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public DpListSvlt() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
			request.setAttribute("tlist", tlist);
			request.getRequestDispatcher("/admin/mgpiao.jsp").forward(request, response);
			return;
		}
		//订票信息管理初始化
		if("dpiao".equals(tname)){
			ResultSet rs=db.query("select dpiao.*,cxzh,ezdid,ezdname,ptype,pval,stime,szdid,szdname,tid,tname,traintype,yxsj from(select tmp.*,zdname as ezdname from(select piao.*,zdname as szdname,tname,traintype  from piao,zhandian,traininfo where piao.tid=traininfo.id and piao.szdid=zhandian.id)tmp,zhandian where tmp.ezdid=zhandian.id)tm,dpiao,cusinfo where tm.id=dpiao.pid and dpiao.cidcard=cusinfo.cidcard");
			List<Dpiao> dplist=FindService.getDpiao(rs);
			request.setAttribute("alist", dplist);
			request.getRequestDispatcher("/admin/mdpiao.jsp").forward(request, response);
			return;
		}
		//登录/注册跳转
		if("dl".equals(tname)){
			String sflag=request.getParameter("sflag");
			request.setAttribute("sflag",sflag );
			request.getRequestDispatcher("/login.jsp").forward(request, response);
			return;
		}
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

				json.put("dt", 0);
				json.put("msg", "tperror:01");
			}
		}else if("del".equals(flgs)){
			int bls=db.deleteOrUpdate("delete from dpiao where id="+id);
			if(bls>0){
				json.put("dt", 1);
				json.put("msg", "删除成功。");
			}else{
				json.put("dt", 0);
				json.put("msg", "tperror:01");
			}
		}else{
			json.put("dt", 0);
		}
		PrintWriter out = response.getWriter();
		out.print(json.toString());
		out.flush();
		out.close();
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

	/**
	 * 读取Properties综合类,默认绑定到temp下的.properties文件。
	 */
	public class HandleProperties {
	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

public class Del extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public Del() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

java毕业

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值