基于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等均可配置运行

适用

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

功能说明

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

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

后台:

前台

技术框架

JSP Servlet MySQL JDBC Tomcat CSS JavaScript

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

			if(!f.exists()){
				try {
					f.createNewFile();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			configPath=f.getPath();
	        FileInputStream in = new FileInputStream(f);
	        props = new Properties();
	        props.load(in);
	        //关闭资源
	        in.close();
	    }
	    
	    /**
	     * 根据key值读取配置的值
	     * @param key key值
	     * @return key 键对应的值 
	     * @throws IOException 
	     */
	    public String readValue(String key) throws IOException {
	        return  props.getProperty(key);
	    }
	    
	    /**
	     * 读取properties的全部信息
	     * @throws FileNotFoundException 配置文件没有找到
	     * @throws IOException 关闭资源文件,或者加载配置文件错误
	     * 
	     */
	    public Map<String,String> readAllProperties() throws FileNotFoundException,IOException  {
	        //保存所有的键值
	        Map<String,String> map=new HashMap<String,String>();
	        Enumeration en = props.propertyNames();
	        while (en.hasMoreElements()) {
	            String key = (String) en.nextElement();
	            String Property = props.getProperty(key);
	            map.put(key, Property);
	        }
	        return map;
	    }


	/**
	 * Constructor of the object.
	 */
	public RegSvlt() {
		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");

	/**
	 * 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");
		HttpSession session=request.getSession();
		//获取当前登录用户信息
		Object utype=session.getAttribute("utype");
		Object userid=session.getAttribute("userid");
		//创建json对象
		JSONObject json=new JSONObject();
	 * Constructor of the object.
	 */
	public UpdSvlt() {
		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");
		HttpSession session=request.getSession();
		//获取当前登录用户信息
	/**
	 * 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>
	 *
	 * 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");
		}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 {
	    //配置文件的路径
	    private String configPath=null;
	    
	    /**
	     * 配置文件对象
	        Properties prop = new Properties();
	        InputStream fis = new FileInputStream(this.configPath);
	        // 从输入流中读取属性列表(键和元素对)
	        prop.load(fis);
	        // 调用 Hashtable 的方法 put。使用 getProperty 方法提供并行性。
	        // 强制要求为属性的键和值使用字符串。返回值是 Hashtable 调用 put 的结果。
	        OutputStream fos = new FileOutputStream(this.configPath);
	        prop.setProperty(key, value);
	        // 以适合使用 load 方法加载到 Properties 表中的格式,
	        // 将此 Properties 表中的属性列表(键和元素对)写入输出流
	        prop.store(fos,"last update");
	        //关闭文件
	        fis.close();
	        fos.close();
	    }
}

public class ChangePwd extends HttpServlet {

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

	/**
	 * Destruction of the servlet. <br>
			}
		}
		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 CusCkSvlt extends HttpServlet {

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

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}
	 * 
	 * @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 un=request.getParameter("uname");
			String up=request.getParameter("upassword");
			boolean bl=db.checkTrue("select id from userinfo where uname='"+un+"'");
			if(bl){
				json.put("msg", "账号已存在");
			}else{
				bl=db.insort("insert into userinfo(uname,upassword) values('"+un+"','"+up+"')");
				if(!bl){
					json.put("msg", "添加成功。");
				}else{
					json.put("msg", "添加失败");
				}
			}
		}
		//顾客信息添加
		if("cusinfo".equals(tname)){
			String un=request.getParameter("cidcard");
			String up=request.getParameter("cpassword");
			String um=request.getParameter("cname");
			boolean bl=db.checkTrue("select id from cusinfo where cidcard='"+un+"'");
			if(bl){
	     */
	    public String readValue(String key) throws IOException {
	        return  props.getProperty(key);
	    }
	    
	    /**
	     * 读取properties的全部信息
	     * @throws FileNotFoundException 配置文件没有找到
	     * @throws IOException 关闭资源文件,或者加载配置文件错误
	     * 
	     */
	    public Map<String,String> readAllProperties() throws FileNotFoundException,IOException  {
	        //保存所有的键值
	        Map<String,String> map=new HashMap<String,String>();
	        Enumeration en = props.propertyNames();
	        while (en.hasMoreElements()) {
	            String key = (String) en.nextElement();
	            String Property = props.getProperty(key);
	            map.put(key, Property);
	        }
	        return map;
	    }

	    /**
	     * 设置某个key的值,并保存至文件。
	     * @param key key值
	     * @return key 键对应的值 
	     * @throws IOException 
	     */
	    public void setValue(String key,String value) throws IOException {
	        Properties prop = new Properties();
	        InputStream fis = new FileInputStream(this.configPath);
	        // 从输入流中读取属性列表(键和元素对)
	        prop.load(fis);
	        // 调用 Hashtable 的方法 put。使用 getProperty 方法提供并行性。
	        // 强制要求为属性的键和值使用字符串。返回值是 Hashtable 调用 put 的结果。
	        OutputStream fos = new FileOutputStream(this.configPath);
	        prop.setProperty(key, value);
	        // 以适合使用 load 方法加载到 Properties 表中的格式,
	        // 将此 Properties 表中的属性列表(键和元素对)写入输出流
	        prop.store(fos,"last update");
		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");
		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 un=request.getParameter("uname");
			String up=request.getParameter("upassword");
			boolean bl=db.checkTrue("select id from userinfo where uname='"+un+"'");
				}
			}else{
				json.put("msg", "操作错误01");
			}
		}
		//火车信息修改
		if("traininfo".equals(tname)){
			String tnames=request.getParameter("tnames");
			String cz=request.getParameter("cz");
			String znums=request.getParameter("znums");
			String xcnums=request.getParameter("xcnums");
			String traintype=request.getParameter("traintype");
			String ids=request.getParameter("idi");
			ResultSet rs=db.query("select id from traininfo where tname='"+tnames+"'");
			if(rs!=null){
				boolean bl=false;
				int id=-1;
				try {
					while(rs.next()){
						id=rs.getInt("id");
						if(!String.valueOf(id).equals(ids)){
							bl=true;
						}
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				if(bl){
					json.put("msg", "车次已注册");
				}else{
					int bls=db.deleteOrUpdate("update traininfo set tname='"+tnames+"', cz='"+cz+"' ,traintype='"+traintype+"',znums="+znums+",xcnums="+xcnums+" where id="+ids);
					if(bls>0){
						json.put("msg", "修改成功。");
					}else{
						json.put("msg", "修改失败");
					}
				}
			}else{
				json.put("msg", "操作错误01");
			}
		}
		//站点信息修改
		if("zhandian".equals(tname)){
			String zdname=request.getParameter("zdname");
			String ids=request.getParameter("idi");
			ResultSet rs=db.query("select id from zhandian where zdname='"+zdname+"'");
			if(rs!=null){
				boolean bl=false;
				int id=-1;
				try {
					while(rs.next()){
						id=rs.getInt("id");
						if(!String.valueOf(id).equals(ids)){
		session.removeAttribute("username");
		session.removeAttribute("utype");
		if("gly".equals(flag)){
			request.getRequestDispatcher("/admin/login.jsp").forward(request, response);
		}else if("cus".equals(flag)){
			request.getRequestDispatcher("/index.jsp").forward(request, response);
		}
	}

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

}

public class InitLoginSvlt extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public InitLoginSvlt() {
		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.
			}else{
				sql=hp.readValue("sql");
			}
			ResultSet rs=db.query(sql);
			List<Traininfo> alist=FindService.getTraininfo(rs);
			request.setAttribute("alist", alist);
			request.getRequestDispatcher("/admin/mgtraininfo.jsp").forward(request, response);
			return;
		}
		//站点信息管理初始化
		if("zhandian".equals(tname)){
			if("1".equals(flgs)){
				sql="select * from zhandian";
				hp.setValue("sql", sql);
			}else{
				sql=hp.readValue("sql");
			}
			ResultSet rs=db.query(sql);
			List<Zhandian> alist=FindService.getZhandian(rs);
			request.setAttribute("alist", alist);
			request.getRequestDispatcher("/admin/mgzhandian.jsp").forward(request, response);
			return;
		}
		//线路信息初始化
		if("initxl".equals(tname)){
			if("1".equals(flgs)){
				sql="select * from traininfo";
				hp.setValue("sql", sql);
			}else{
				sql=hp.readValue("sql");
			}
			List<Xianlu> xllist=new ArrayList();
			DbConn db2=new DbConn();
			ResultSet rs=db.query(sql);
			List<Traininfo> tlist=FindService.getTraininfo(rs);
			Iterator<Traininfo> it=tlist.iterator();
			while(it.hasNext()){
				Traininfo t=it.next();
				Xianlu xl=new Xianlu();
				xl.setTid(t.getId());
				xl.setTname(t.getTname());
				ResultSet rs2=db2.query("select zhandian.*,xh from xianlu,zhandian where xianlu.zdid=zhandian.id and xianlu.tid="+t.getId()+" order by xh");
				List<Zhandian> zdlist=FindService.getZhandian(rs2);
				xl.setZdlist(zdlist);
				xllist.add(xl);
	/**
	 * 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");
		HttpSession session=request.getSession();
		//获取当前登录用户信息
		Object utype=session.getAttribute("utype");
			}else{
				json.put("msg", "操作错误01");
			}
		}
		//火车信息修改
		if("traininfo".equals(tname)){
			String tnames=request.getParameter("tnames");
			String cz=request.getParameter("cz");
			String znums=request.getParameter("znums");
			String xcnums=request.getParameter("xcnums");
			String traintype=request.getParameter("traintype");
			String ids=request.getParameter("idi");
			ResultSet rs=db.query("select id from traininfo where tname='"+tnames+"'");
			if(rs!=null){
				boolean bl=false;
				int id=-1;
				try {
					while(rs.next()){
						id=rs.getInt("id");
						if(!String.valueOf(id).equals(ids)){
							bl=true;
						}
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				if(bl){
					json.put("msg", "车次已注册");
				}else{
					int bls=db.deleteOrUpdate("update traininfo set tname='"+tnames+"', cz='"+cz+"' ,traintype='"+traintype+"',znums="+znums+",xcnums="+xcnums+" where id="+ids);
					if(bls>0){
						json.put("msg", "修改成功。");
					}else{
						json.put("msg", "修改失败");
					}
				}
			}else{
				json.put("msg", "操作错误01");
			}
		}
		//站点信息修改
		if("zhandian".equals(tname)){
			String zdname=request.getParameter("zdname");
			String ids=request.getParameter("idi");
			ResultSet rs=db.query("select id from zhandian where zdname='"+zdname+"'");
			if(rs!=null){
				boolean bl=false;
				int id=-1;
	public LogoutSvlt() {
		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 {

		response.setContentType("text/html");
		HttpSession session=request.getSession();
		String flag=request.getParameter("flag");
		session.removeAttribute("userid");

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

  • 0
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值