作者主页:源码空间站2022
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
这个项目是一个基于Servlet+JSP的电影院售票系统,分为管理员和会员两种角色。
管理员权限包括:
修改登录密码
电影类别管理
电影信息管理
会员信息管理
订单信息管理
留言信息管理
会员权限包括:
会员注册
会员登录
浏览电影
我的购物车
我的订单
留言板
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
Servlet、JSP、JDBC、MySQL5.7、Tomcat8
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,然后运行;
3. 将项目中src/com/dao/DB.java配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入localhost:8080/goupiao
管理员账号/密码:admin/admin
会员账号/密码:zhangsan/123456
- package com.action;
-
- import java.io.IOException;
- import java.sql.ResultSet;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.Iterator;
- import java.util.List;
-
- import javax.servlet.RequestDispatcher;
- import javax.servlet.ServletConfig;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
-
- import com.orm.Tgoods;
- import com.orm.Torder;
- import com.orm.TorderItem;
- import com.orm.Tuser;
- import com.service.liuService;
- import com.util.Cart;
-
- public class buy_servlet extends HttpServlet
- {
-
- public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
- {
- String type=req.getParameter("type");
-
- if(type.endsWith("addToCart"))
- {
- addToCart(req, res);
- }
- if(type.endsWith("orderSubmit"))
- {
- orderSubmit(req, res);
- }
- if(type.endsWith("myorder"))
- {
- myorder(req, res);
- }
- if(type.endsWith("orderDetail"))
- {
- orderDetail(req, res);
- }
- }
-
-
- public void addToCart(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
- {
- String goods_id=req.getParameter("goods_id");
- int quantity=Integer.parseInt(req.getParameter("quantity"));
- Tgoods goods=liuService.getGoods(goods_id);
-
- TorderItem orderItem=new TorderItem();
- orderItem.setGoods(goods);
- orderItem.setGoods_quantity(quantity);
-
- HttpSession session=req.getSession();
- Cart cart =(Cart)session.getAttribute("cart");
- cart.addGoods(goods_id, orderItem);
-
- session.setAttribute("cart", cart);
-
- req.setAttribute("message", "操作成功");
- req.setAttribute("path", "site/cart/mycart.jsp");
-
- String targetURL = "/common/success.jsp";
- dispatch(targetURL, req, res);
-
- }
-
-
-
- public void orderSubmit(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
- {
- String songhuodizhi=req.getParameter("songhuodizhi");
- String fukuanfangshi=req.getParameter("fukuanfangshi");
-
- HttpSession session=req.getSession();
- Cart cart =(Cart)session.getAttribute("cart");
- Tuser user=(Tuser)session.getAttribute("user");
-
- Torder order=new Torder();
- order.setId(String.valueOf(new Date().getTime()));
- order.setBianhao(new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()));
- order.setShijian(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
- order.setZhuangtai("no");
- order.setSonghuodizhi(songhuodizhi);
- order.setFukuanfangshi(fukuanfangshi);
- order.setJine(cart.getTotalPrice());
- order.setUser_id(user.getId());
- liuService.saveOrder(order);
-
- for (Iterator it = cart.getItems().values().iterator(); it.hasNext();)
- {
-
- TorderItem orderItem = (TorderItem) it.next();
-
- String id=String.valueOf(new Date().getTime());
- String order_id=order.getId();
- String goods_id=orderItem.getGoods().getId();
- int goods_quantity=orderItem.getGoods_quantity();
- liuService.saveOrderItem(id, order_id, goods_id, goods_quantity);
-
- liuService.updateGoodsKucun(goods_id, goods_quantity);
- }
-
- cart.getItems().clear();
- session.setAttribute("cart", cart);
-
- req.setAttribute("order", order);
- req.getRequestDispatcher("site/order/orderSubmit.jsp").forward(req, res);
- }
-
-
- public void myorder(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
- {
- HttpSession session=req.getSession();
- Tuser user=(Tuser)session.getAttribute("user");
-
- req.setAttribute("orderList", liuService.orderList(user.getId()));
- req.getRequestDispatcher("site/order/myorder.jsp").forward(req, res);
- }
-
- public void orderDetail(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
- {
- String order_id=req.getParameter("order_id");
- System.out.println(order_id+"DD");
- req.setAttribute("orderItemList", liuService.orderItemList(order_id));
- req.getRequestDispatcher("site/order/orderDetail.jsp").forward(req, res);
- }
-
-
- public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response)
- {
- RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
- try
- {
- dispatch.forward(request, response);
- return;
- }
- catch (ServletException e)
- {
- e.printStackTrace();
- }
- catch (IOException e)
- {
-
- e.printStackTrace();
- }
- }
- public void init(ServletConfig config) throws ServletException
- {
- super.init(config);
- }
-
- public void destroy()
- {
-
- }
- }
- package com.action;
-
- import java.io.IOException;
- import java.sql.ResultSet;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
-
- import javax.servlet.RequestDispatcher;
- import javax.servlet.ServletConfig;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
-
- import com.dao.DB;
- import com.orm.Tcatelog;
-
-
- public class catelog_servlet extends HttpServlet
- {
- public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
- {
- String type=req.getParameter("type");
-
- if(type.endsWith("catelogAdd"))
- {
- catelogAdd(req, res);
- }
- if(type.endsWith("catelogMana"))
- {
- catelogMana(req, res);
- }
- if(type.endsWith("catelogDel"))
- {
- catelogDel(req, res);
- }
- }
-
- public void catelogAdd(HttpServletRequest req,HttpServletResponse res)
- {
- String id=String.valueOf(new Date().getTime());
- String name=req.getParameter("name").trim();
- String del="no";
-
- String sql="insert into t_catelog(id,name,del) values(?,?,?)";
- Object[] params={id,name,del};
- DB mydb=new DB();
- mydb.doPstm(sql, params);
- mydb.closed();
-
- req.setAttribute("msg", "操作成功");
- String targetURL = "/common/msg.jsp";
- dispatch(targetURL, req, res);
- }
-
-
- public void catelogMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
- {
- List catelogList=new ArrayList();
- String sql="select * from t_catelog where del='no'";
- Object[] params={};
- DB mydb=new DB();
- try
- {
- mydb.doPstm(sql, params);
- ResultSet rs=mydb.getRs();
- while(rs.next())
- {
- Tcatelog catelog=new Tcatelog();
- catelog.setId(rs.getString("id"));
- catelog.setName(rs.getString("name"));
- catelogList.add(catelog);
- }
- rs.close();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- mydb.closed();
-
- req.setAttribute("catelogList", catelogList);
- req.getRequestDispatcher("admin/catelog/catelogMana.jsp").forward(req, res);
- }
-
-
-
- public void catelogDel(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
- {
- String sql="update t_catelog set del='yes' where id="+req.getParameter("id");
- Object[] params={};
- DB mydb=new DB();
- mydb.doPstm(sql, params);
- mydb.closed();
-
- req.setAttribute("msg", "操作成功");
- String targetURL = "/common/msg.jsp";
- dispatch(targetURL, req, res);
- }
-
-
- public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response)
- {
- RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
- try
- {
- dispatch.forward(request, response);
- return;
- }
- catch (ServletException e)
- {
- e.printStackTrace();
- }
- catch (IOException e)
- {
-
- e.printStackTrace();
- }
- }
- public void init(ServletConfig config) throws ServletException
- {
- super.init(config);
- }
-
- public void destroy()
- {
-
- }
- }
- package com.action;
-
- import java.io.IOException;
- import java.sql.ResultSet;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
-
- import javax.servlet.RequestDispatcher;
- import javax.servlet.ServletConfig;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
-
- import com.dao.DB;
- import com.orm.Tgoods;
- import com.service.liuService;
-
-
- public class goods_servlet extends HttpServlet
- {
- public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
- {
- String type=req.getParameter("type");
-
- if(type.endsWith("goodsAdd"))
- {
- goodsAdd(req, res);
- }
- if(type.endsWith("goodsMana"))
- {
- goodsMana(req, res);
- }
- if(type.endsWith("goodsDel"))
- {
- goodsDel(req, res);
- }
- if(type.endsWith("goodsDetailHou"))
- {
- goodsDetailHou(req, res);
- }
-
- if(type.endsWith("goodsAll"))
- {
- goodsAll(req, res);
- }
- if(type.endsWith("goodsByCatelog"))
- {
- goodsByCatelog(req, res);
- }
- if(type.endsWith("goodsDetailQian"))
- {
- goodsDetailQian(req, res);
- }
- }
-
- public void goodsAdd(HttpServletRequest req,HttpServletResponse res)
- {
- String id=String.valueOf(new Date().getTime());
- String fangyingshi=req.getParameter("fangyingshi");
- String catelog_id=req.getParameter("catelog_id");
- String mingcheng=req.getParameter("mingcheng");
-
- String jieshao=req.getParameter("jieshao");
- String fujian=req.getParameter("fujian");
- int shichangjia=Integer.parseInt(req.getParameter("shichangjia"));
- int tejia=Integer.parseInt(req.getParameter("shichangjia"));
-
-
- String del="no";
-
- String sql="insert into t_goods(id,fangyingshi,catelog_id,mingcheng,jieshao,fujian,shichangjia,tejia,del) " +
- "values(?,?,?,?,?,?,?,?,?)";
- Object[] params={id,fangyingshi,catelog_id,mingcheng,jieshao,fujian,shichangjia,tejia,del};
- DB mydb=new DB();
- mydb.doPstm(sql, params);
- mydb.closed();
-
- req.setAttribute("msg", "操作成功");
- String targetURL = "/common/msg.jsp";
- dispatch(targetURL, req, res);
- }
-
-
- public void goodsMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
- {
- List goodsList=new ArrayList();
- String sql="select * from t_goods where del='no' order by fangyingshi desc";
- Object[] params={};
- DB mydb=new DB();
- try
- {
- mydb.doPstm(sql, params);
- ResultSet rs=mydb.getRs();
- while(rs.next())
- {
- Tgoods goods=new Tgoods();
-
- goods.setId(rs.getString("id"));
- goods.setFangyingshi(rs.getString("fangyingshi"));
- goods.setCatelog_id(rs.getString("catelog_id"));
-
- goods.setMingcheng(rs.getString("mingcheng"));
- goods.setJieshao(rs.getString("jieshao"));
- goods.setFujian(rs.getString("fujian"));
-
- goods.setShichangjia(rs.getInt("shichangjia"));
- goods.setTejia(rs.getInt("tejia"));
- goods.setDel(rs.getString("del"));
-
- goodsList.add(goods);
- }
- rs.close();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- mydb.closed();
-
- req.setAttribute("goodsList", goodsList);
- req.getRequestDispatcher("admin/goods/goodsMana.jsp").forward(req, res);
- }
-
-
-
- public void goodsDel(HttpServletRequest req,HttpServletResponse res)
- {
- String id=req.getParameter("id");
- String sql="update t_goods set del='yes' where id="+id;
- Object[] params={};
- DB mydb=new DB();
- mydb.doPstm(sql, params);
- mydb.closed();
-
- req.setAttribute("msg", "操作成功");
- String targetURL = "/common/msg.jsp";
- dispatch(targetURL, req, res);
- }
-
-
- public void goodsDetailHou(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
- {
- String id=req.getParameter("id");
-
- req.setAttribute("goods", liuService.getGoods(id));
- req.getRequestDispatcher("admin/goods/goodsDetailHou.jsp").forward(req, res);
- }
-
-
- public void goodsAll(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
- {
- List goodsList=new ArrayList();
- //String sql="select * from t_goods where del='no' and fangyingshi >? order by fangyingshi desc";
- String sql="select * from t_goods where del='no' order by fangyingshi desc";
- Object[] params={new SimpleDateFormat("yyyy-MM-dd").format(new Date())};
- DB mydb=new DB();
- try
- {
- mydb.doPstm(sql, null);
- ResultSet rs=mydb.getRs();
- while(rs.next())
- {
- Tgoods goods=new Tgoods();
-
- goods.setId(rs.getString("id"));
- goods.setFangyingshi(rs.getString("fangyingshi"));
- goods.setCatelog_id(rs.getString("catelog_id"));
-
- goods.setMingcheng(rs.getString("mingcheng"));
- goods.setJieshao(rs.getString("jieshao"));
- goods.setFujian(rs.getString("fujian"));
-
- goods.setShichangjia(rs.getInt("shichangjia"));
- goods.setTejia(rs.getInt("tejia"));
- goods.setDel(rs.getString("del"));
-
- goodsList.add(goods);
- }
- rs.close();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- mydb.closed();
-
- if(goodsList.size()>8)
- {
- goodsList=goodsList.subList(0, 8);
- }
-
- req.setAttribute("goodsList", goodsList);
- req.getRequestDispatcher("site/goods/goodsAll.jsp").forward(req, res);
- }
-
-
-
-
- public void goodsByCatelog(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
- {
- String catelog_id=req.getParameter("catelog_id");
-
- req.setAttribute("goodsList", liuService.goodsByCatelog(catelog_id));
- req.getRequestDispatcher("site/goods/goodsByCatelog.jsp").forward(req, res);
- }
-
- public void goodsDetailQian(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
- {
- String id=req.getParameter("id");
-
- req.setAttribute("goods", liuService.getGoods(id));
- req.getRequestDispatcher("site/goods/goodsDetailQian.jsp").forward(req, res);
- }
-
-
- public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response)
- {
- RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
- try
- {
- dispatch.forward(request, response);
- return;
- }
- catch (ServletException e)
- {
- e.printStackTrace();
- }
- catch (IOException e)
- {
-
- e.printStackTrace();
- }
- }
- public void init(ServletConfig config) throws ServletException
- {
- super.init(config);
- }
-
- public void destroy()
- {
-
- }
- }
如果也想学习本系统,下面领取。关注并回复:131jsp