• Java项目:JSP的电影院售票系统(含论文、任务书、中期检查表)


    作者主页:源码空间站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

    运行截图

    前台界面

    后台界面

    相关代码 

    buy_servlet

    1. package com.action;
    2. import java.io.IOException;
    3. import java.sql.ResultSet;
    4. import java.text.SimpleDateFormat;
    5. import java.util.ArrayList;
    6. import java.util.Date;
    7. import java.util.Iterator;
    8. import java.util.List;
    9. import javax.servlet.RequestDispatcher;
    10. import javax.servlet.ServletConfig;
    11. import javax.servlet.ServletException;
    12. import javax.servlet.http.HttpServlet;
    13. import javax.servlet.http.HttpServletRequest;
    14. import javax.servlet.http.HttpServletResponse;
    15. import javax.servlet.http.HttpSession;
    16. import com.orm.Tgoods;
    17. import com.orm.Torder;
    18. import com.orm.TorderItem;
    19. import com.orm.Tuser;
    20. import com.service.liuService;
    21. import com.util.Cart;
    22. public class buy_servlet extends HttpServlet
    23. {
    24. public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
    25. {
    26. String type=req.getParameter("type");
    27. if(type.endsWith("addToCart"))
    28. {
    29. addToCart(req, res);
    30. }
    31. if(type.endsWith("orderSubmit"))
    32. {
    33. orderSubmit(req, res);
    34. }
    35. if(type.endsWith("myorder"))
    36. {
    37. myorder(req, res);
    38. }
    39. if(type.endsWith("orderDetail"))
    40. {
    41. orderDetail(req, res);
    42. }
    43. }
    44. public void addToCart(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
    45. {
    46. String goods_id=req.getParameter("goods_id");
    47. int quantity=Integer.parseInt(req.getParameter("quantity"));
    48. Tgoods goods=liuService.getGoods(goods_id);
    49. TorderItem orderItem=new TorderItem();
    50. orderItem.setGoods(goods);
    51. orderItem.setGoods_quantity(quantity);
    52. HttpSession session=req.getSession();
    53. Cart cart =(Cart)session.getAttribute("cart");
    54. cart.addGoods(goods_id, orderItem);
    55. session.setAttribute("cart", cart);
    56. req.setAttribute("message", "操作成功");
    57. req.setAttribute("path", "site/cart/mycart.jsp");
    58. String targetURL = "/common/success.jsp";
    59. dispatch(targetURL, req, res);
    60. }
    61. public void orderSubmit(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
    62. {
    63. String songhuodizhi=req.getParameter("songhuodizhi");
    64. String fukuanfangshi=req.getParameter("fukuanfangshi");
    65. HttpSession session=req.getSession();
    66. Cart cart =(Cart)session.getAttribute("cart");
    67. Tuser user=(Tuser)session.getAttribute("user");
    68. Torder order=new Torder();
    69. order.setId(String.valueOf(new Date().getTime()));
    70. order.setBianhao(new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()));
    71. order.setShijian(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
    72. order.setZhuangtai("no");
    73. order.setSonghuodizhi(songhuodizhi);
    74. order.setFukuanfangshi(fukuanfangshi);
    75. order.setJine(cart.getTotalPrice());
    76. order.setUser_id(user.getId());
    77. liuService.saveOrder(order);
    78. for (Iterator it = cart.getItems().values().iterator(); it.hasNext();)
    79. {
    80. TorderItem orderItem = (TorderItem) it.next();
    81. String id=String.valueOf(new Date().getTime());
    82. String order_id=order.getId();
    83. String goods_id=orderItem.getGoods().getId();
    84. int goods_quantity=orderItem.getGoods_quantity();
    85. liuService.saveOrderItem(id, order_id, goods_id, goods_quantity);
    86. liuService.updateGoodsKucun(goods_id, goods_quantity);
    87. }
    88. cart.getItems().clear();
    89. session.setAttribute("cart", cart);
    90. req.setAttribute("order", order);
    91. req.getRequestDispatcher("site/order/orderSubmit.jsp").forward(req, res);
    92. }
    93. public void myorder(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
    94. {
    95. HttpSession session=req.getSession();
    96. Tuser user=(Tuser)session.getAttribute("user");
    97. req.setAttribute("orderList", liuService.orderList(user.getId()));
    98. req.getRequestDispatcher("site/order/myorder.jsp").forward(req, res);
    99. }
    100. public void orderDetail(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
    101. {
    102. String order_id=req.getParameter("order_id");
    103. System.out.println(order_id+"DD");
    104. req.setAttribute("orderItemList", liuService.orderItemList(order_id));
    105. req.getRequestDispatcher("site/order/orderDetail.jsp").forward(req, res);
    106. }
    107. public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response)
    108. {
    109. RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
    110. try
    111. {
    112. dispatch.forward(request, response);
    113. return;
    114. }
    115. catch (ServletException e)
    116. {
    117. e.printStackTrace();
    118. }
    119. catch (IOException e)
    120. {
    121. e.printStackTrace();
    122. }
    123. }
    124. public void init(ServletConfig config) throws ServletException
    125. {
    126. super.init(config);
    127. }
    128. public void destroy()
    129. {
    130. }
    131. }

    catelog_servlet

    1. package com.action;
    2. import java.io.IOException;
    3. import java.sql.ResultSet;
    4. import java.util.ArrayList;
    5. import java.util.Date;
    6. import java.util.List;
    7. import javax.servlet.RequestDispatcher;
    8. import javax.servlet.ServletConfig;
    9. import javax.servlet.ServletException;
    10. import javax.servlet.http.HttpServlet;
    11. import javax.servlet.http.HttpServletRequest;
    12. import javax.servlet.http.HttpServletResponse;
    13. import com.dao.DB;
    14. import com.orm.Tcatelog;
    15. public class catelog_servlet extends HttpServlet
    16. {
    17. public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
    18. {
    19. String type=req.getParameter("type");
    20. if(type.endsWith("catelogAdd"))
    21. {
    22. catelogAdd(req, res);
    23. }
    24. if(type.endsWith("catelogMana"))
    25. {
    26. catelogMana(req, res);
    27. }
    28. if(type.endsWith("catelogDel"))
    29. {
    30. catelogDel(req, res);
    31. }
    32. }
    33. public void catelogAdd(HttpServletRequest req,HttpServletResponse res)
    34. {
    35. String id=String.valueOf(new Date().getTime());
    36. String name=req.getParameter("name").trim();
    37. String del="no";
    38. String sql="insert into t_catelog(id,name,del) values(?,?,?)";
    39. Object[] params={id,name,del};
    40. DB mydb=new DB();
    41. mydb.doPstm(sql, params);
    42. mydb.closed();
    43. req.setAttribute("msg", "操作成功");
    44. String targetURL = "/common/msg.jsp";
    45. dispatch(targetURL, req, res);
    46. }
    47. public void catelogMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
    48. {
    49. List catelogList=new ArrayList();
    50. String sql="select * from t_catelog where del='no'";
    51. Object[] params={};
    52. DB mydb=new DB();
    53. try
    54. {
    55. mydb.doPstm(sql, params);
    56. ResultSet rs=mydb.getRs();
    57. while(rs.next())
    58. {
    59. Tcatelog catelog=new Tcatelog();
    60. catelog.setId(rs.getString("id"));
    61. catelog.setName(rs.getString("name"));
    62. catelogList.add(catelog);
    63. }
    64. rs.close();
    65. }
    66. catch(Exception e)
    67. {
    68. e.printStackTrace();
    69. }
    70. mydb.closed();
    71. req.setAttribute("catelogList", catelogList);
    72. req.getRequestDispatcher("admin/catelog/catelogMana.jsp").forward(req, res);
    73. }
    74. public void catelogDel(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
    75. {
    76. String sql="update t_catelog set del='yes' where id="+req.getParameter("id");
    77. Object[] params={};
    78. DB mydb=new DB();
    79. mydb.doPstm(sql, params);
    80. mydb.closed();
    81. req.setAttribute("msg", "操作成功");
    82. String targetURL = "/common/msg.jsp";
    83. dispatch(targetURL, req, res);
    84. }
    85. public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response)
    86. {
    87. RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
    88. try
    89. {
    90. dispatch.forward(request, response);
    91. return;
    92. }
    93. catch (ServletException e)
    94. {
    95. e.printStackTrace();
    96. }
    97. catch (IOException e)
    98. {
    99. e.printStackTrace();
    100. }
    101. }
    102. public void init(ServletConfig config) throws ServletException
    103. {
    104. super.init(config);
    105. }
    106. public void destroy()
    107. {
    108. }
    109. }

    goods_servlet

    1. package com.action;
    2. import java.io.IOException;
    3. import java.sql.ResultSet;
    4. import java.text.SimpleDateFormat;
    5. import java.util.ArrayList;
    6. import java.util.Date;
    7. import java.util.List;
    8. import javax.servlet.RequestDispatcher;
    9. import javax.servlet.ServletConfig;
    10. import javax.servlet.ServletException;
    11. import javax.servlet.http.HttpServlet;
    12. import javax.servlet.http.HttpServletRequest;
    13. import javax.servlet.http.HttpServletResponse;
    14. import com.dao.DB;
    15. import com.orm.Tgoods;
    16. import com.service.liuService;
    17. public class goods_servlet extends HttpServlet
    18. {
    19. public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
    20. {
    21. String type=req.getParameter("type");
    22. if(type.endsWith("goodsAdd"))
    23. {
    24. goodsAdd(req, res);
    25. }
    26. if(type.endsWith("goodsMana"))
    27. {
    28. goodsMana(req, res);
    29. }
    30. if(type.endsWith("goodsDel"))
    31. {
    32. goodsDel(req, res);
    33. }
    34. if(type.endsWith("goodsDetailHou"))
    35. {
    36. goodsDetailHou(req, res);
    37. }
    38. if(type.endsWith("goodsAll"))
    39. {
    40. goodsAll(req, res);
    41. }
    42. if(type.endsWith("goodsByCatelog"))
    43. {
    44. goodsByCatelog(req, res);
    45. }
    46. if(type.endsWith("goodsDetailQian"))
    47. {
    48. goodsDetailQian(req, res);
    49. }
    50. }
    51. public void goodsAdd(HttpServletRequest req,HttpServletResponse res)
    52. {
    53. String id=String.valueOf(new Date().getTime());
    54. String fangyingshi=req.getParameter("fangyingshi");
    55. String catelog_id=req.getParameter("catelog_id");
    56. String mingcheng=req.getParameter("mingcheng");
    57. String jieshao=req.getParameter("jieshao");
    58. String fujian=req.getParameter("fujian");
    59. int shichangjia=Integer.parseInt(req.getParameter("shichangjia"));
    60. int tejia=Integer.parseInt(req.getParameter("shichangjia"));
    61. String del="no";
    62. String sql="insert into t_goods(id,fangyingshi,catelog_id,mingcheng,jieshao,fujian,shichangjia,tejia,del) " +
    63. "values(?,?,?,?,?,?,?,?,?)";
    64. Object[] params={id,fangyingshi,catelog_id,mingcheng,jieshao,fujian,shichangjia,tejia,del};
    65. DB mydb=new DB();
    66. mydb.doPstm(sql, params);
    67. mydb.closed();
    68. req.setAttribute("msg", "操作成功");
    69. String targetURL = "/common/msg.jsp";
    70. dispatch(targetURL, req, res);
    71. }
    72. public void goodsMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
    73. {
    74. List goodsList=new ArrayList();
    75. String sql="select * from t_goods where del='no' order by fangyingshi desc";
    76. Object[] params={};
    77. DB mydb=new DB();
    78. try
    79. {
    80. mydb.doPstm(sql, params);
    81. ResultSet rs=mydb.getRs();
    82. while(rs.next())
    83. {
    84. Tgoods goods=new Tgoods();
    85. goods.setId(rs.getString("id"));
    86. goods.setFangyingshi(rs.getString("fangyingshi"));
    87. goods.setCatelog_id(rs.getString("catelog_id"));
    88. goods.setMingcheng(rs.getString("mingcheng"));
    89. goods.setJieshao(rs.getString("jieshao"));
    90. goods.setFujian(rs.getString("fujian"));
    91. goods.setShichangjia(rs.getInt("shichangjia"));
    92. goods.setTejia(rs.getInt("tejia"));
    93. goods.setDel(rs.getString("del"));
    94. goodsList.add(goods);
    95. }
    96. rs.close();
    97. }
    98. catch(Exception e)
    99. {
    100. e.printStackTrace();
    101. }
    102. mydb.closed();
    103. req.setAttribute("goodsList", goodsList);
    104. req.getRequestDispatcher("admin/goods/goodsMana.jsp").forward(req, res);
    105. }
    106. public void goodsDel(HttpServletRequest req,HttpServletResponse res)
    107. {
    108. String id=req.getParameter("id");
    109. String sql="update t_goods set del='yes' where id="+id;
    110. Object[] params={};
    111. DB mydb=new DB();
    112. mydb.doPstm(sql, params);
    113. mydb.closed();
    114. req.setAttribute("msg", "操作成功");
    115. String targetURL = "/common/msg.jsp";
    116. dispatch(targetURL, req, res);
    117. }
    118. public void goodsDetailHou(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
    119. {
    120. String id=req.getParameter("id");
    121. req.setAttribute("goods", liuService.getGoods(id));
    122. req.getRequestDispatcher("admin/goods/goodsDetailHou.jsp").forward(req, res);
    123. }
    124. public void goodsAll(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
    125. {
    126. List goodsList=new ArrayList();
    127. //String sql="select * from t_goods where del='no' and fangyingshi >? order by fangyingshi desc";
    128. String sql="select * from t_goods where del='no' order by fangyingshi desc";
    129. Object[] params={new SimpleDateFormat("yyyy-MM-dd").format(new Date())};
    130. DB mydb=new DB();
    131. try
    132. {
    133. mydb.doPstm(sql, null);
    134. ResultSet rs=mydb.getRs();
    135. while(rs.next())
    136. {
    137. Tgoods goods=new Tgoods();
    138. goods.setId(rs.getString("id"));
    139. goods.setFangyingshi(rs.getString("fangyingshi"));
    140. goods.setCatelog_id(rs.getString("catelog_id"));
    141. goods.setMingcheng(rs.getString("mingcheng"));
    142. goods.setJieshao(rs.getString("jieshao"));
    143. goods.setFujian(rs.getString("fujian"));
    144. goods.setShichangjia(rs.getInt("shichangjia"));
    145. goods.setTejia(rs.getInt("tejia"));
    146. goods.setDel(rs.getString("del"));
    147. goodsList.add(goods);
    148. }
    149. rs.close();
    150. }
    151. catch(Exception e)
    152. {
    153. e.printStackTrace();
    154. }
    155. mydb.closed();
    156. if(goodsList.size()>8)
    157. {
    158. goodsList=goodsList.subList(0, 8);
    159. }
    160. req.setAttribute("goodsList", goodsList);
    161. req.getRequestDispatcher("site/goods/goodsAll.jsp").forward(req, res);
    162. }
    163. public void goodsByCatelog(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
    164. {
    165. String catelog_id=req.getParameter("catelog_id");
    166. req.setAttribute("goodsList", liuService.goodsByCatelog(catelog_id));
    167. req.getRequestDispatcher("site/goods/goodsByCatelog.jsp").forward(req, res);
    168. }
    169. public void goodsDetailQian(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
    170. {
    171. String id=req.getParameter("id");
    172. req.setAttribute("goods", liuService.getGoods(id));
    173. req.getRequestDispatcher("site/goods/goodsDetailQian.jsp").forward(req, res);
    174. }
    175. public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response)
    176. {
    177. RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
    178. try
    179. {
    180. dispatch.forward(request, response);
    181. return;
    182. }
    183. catch (ServletException e)
    184. {
    185. e.printStackTrace();
    186. }
    187. catch (IOException e)
    188. {
    189. e.printStackTrace();
    190. }
    191. }
    192. public void init(ServletConfig config) throws ServletException
    193. {
    194. super.init(config);
    195. }
    196. public void destroy()
    197. {
    198. }
    199. }

    如果也想学习本系统,下面领取。关注并回复:131jsp

     

  • 相关阅读:
    ubuntu 22 Docker部署Nacos
    Git如何上传代码至GitHub
    nasa教学纳卫星计划-36
    redis的淘汰机制分析
    传奇游戏常见问题解决办法
    C语言和Java中RSA算法一些注意事项
    MySQL数据库——日志管理、备份与恢复
    【python&flask-1】简单实现加减乘除输入界面
    9月9日,每日信息差
    行业“卷不动”、市场“换不动”,家电赛道又跑回“老路”
  • 原文地址:https://blog.csdn.net/m0_74967853/article/details/128073781