package com.ly.web;
import com.ly.entity.*;
import com.ly.service.OrderService;
import com.ly.service.impl.OrderServiceImpl;
import com.ly.utils.WebBeanUtil;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
public class OrderServlet extends BaseServlet{
OrderService orderService = new OrderServiceImpl();
protected void createOrder(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//获取购物车对象
Car car = (Car) req.getSession().getAttribute("car");
//获取用户id
User loginUser = (User) req.getSession().getAttribute("user");
if (loginUser==null){
req.getRequestDispatcher("/pages/user/login.jsp").forward(req,resp);
return;
}
System.out.println("orderServlet程序在"+Thread.currentThread().getName());
Integer userId = loginUser.getId();
//调用order service生成订单
String orderId = orderService.createOrder(car,userId);
// req.setAttribute("orderId",orderId);
// //请求转发到checkout.jsp中
// req.getRequestDispatcher("/pages/cart/checkout.jsp").forward(req,resp);
//解决表单重复提交问题
req.getSession().setAttribute("orderId",orderId);
resp.sendRedirect(req.getContextPath()+"/pages/cart/checkout.jsp");
}
protected void queryAllOrders(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
User loginUser = (User) req.getSession().getAttribute("user");
if (loginUser==null){
req.getRequestDispatcher("/pages/user/login.jsp").forward(req,resp);
return;
}
int userId = loginUser.getId();
List<Order> order = (List<Order>) orderService.queryOrders(userId);
req.setAttribute("order",order);
req.getRequestDispatcher("/pages/order/order.jsp").forward(req,resp);
}
protected void queryOrderItems(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String orderId = req.getParameter("orderId");
List<OrderItem> orderItem = (List<OrderItem>) orderService.queryOrderItemsByOrderId(orderId);
System.out.println(orderItem);
req.setAttribute("orderItem",orderItem);
req.getRequestDispatcher("/pages/order/order_details.jsp").forward(req,resp);
}
protected void allOrders(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
List<Order> orders = (List<Order>) orderService.queryAll();
req.setAttribute("orders",orders);
req.getRequestDispatcher("/pages/manager/order_manager.jsp").forward(req,resp);
}
protected void sendOrder(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String orderId = req.getParameter("orderId");
req.getSession().setAttribute("orderId",orderId);
Order order = orderService.queryOrderByOrderId(orderId);
orderService.sendOrder(orderId);
req.getRequestDispatcher("orderServlet?action=allOrders").forward(req,resp);
}
protected void receiveOrder(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String orderId = req.getParameter("orderId");
User loginUser = (User) req.getSession().getAttribute("user");
if (loginUser==null){
req.getRequestDispatcher("/pages/user/login.jsp").forward(req,resp);
return;
}
int userId = loginUser.getId();
Order order = orderService.queryOrderByOrderId(orderId);
orderService.receiveOrder(orderId);
req.getRequestDispatcher("orderServlet?action=queryAllOrders&userId=userId").forward(req,resp);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
javaweb教程网上书城项目
共221个文件
java:43个
jsp:21个
sample:13个
需积分: 0 1 下载量 128 浏览量
2022-07-14
23:34:36
上传
评论 1
收藏 14.36MB ZIP 举报
温馨提示
适合还未学习后端框架的小伙伴,订单模块完整,因个人能力问题在为JDBCUtils添加threadlocal和filter的联用时数据库报了并发,表锁相关的错误,解决不了,所以这个版本是没有数据库异常拦截器的版本,但是订单模块是完善了的,如果有感兴趣的高手在学习这个阶段的过程成遇到了上面提到的问题,请给我个链接,真的特别想解决,还有就是老师教程时购物车模块用的时保存到session域中,且有多个是否登录判断时根据浏览器session中的user来判断,所以同一个浏览器不能登录两个不同的用户
资源详情
资源评论
资源推荐
收起资源包目录
javaweb教程网上书城项目 (221个子文件)
05e893c1980abdabab3fffa83e214c08c86c07 186B
0a98371aeb5eccd161381a885309320d863c44 162B
0b1a42c7cd40eaa5f532b8d81072fbe7bd2e06 3.3MB
0cb19aa9ee89074277bb39a3c759a1dbf6692f 2.18MB
11aedc117cb9152aa8bdde6d038e37dad07dfd 365B
12eca739bb9c4f28dc3237b9423f3fe1d4a256 221B
19b663689a4cd435e30995ef25a1d1f98c5574 249B
1c8263c01027c4b5aa662171e48b2337643678 1KB
1d03b07a07dd767e1c48c795ff1576906c9a44 249B
26fdf83b56bc9536e5ebb737716ad54a267a89 642B
271066e45f706ea14f328e4c0ebd654253840f 147B
283729bcf697ca9d22c3e3e926cbb7eb6b3ecf 118B
2877ecfe103ea1d93341b4762a027ca1f9ef1a 1KB
2931df0774e7df132c5b99e24f17d57afc8be4 123B
2b0560af2ca3da086b56ea3c6c5be5c85da67a 1KB
2e2335e9cd1a279176ae084948f03ecf1f85c1 150B
308e0cd5a42750f2dbb25d426efb134829151a 269B
34067b33ea3baf1a07cc788f3771c279876243 351B
351a4ea86377697dffd71dc453251d4681d188 949B
3771518f5a12380bb8034c613d90070917a177 220B
3e13c69901ed7bd14748f902eb61274611d017 36KB
4097e68d7b4ac6f7c8d3353c8a924043fc8d3b 102B
483cfc37e24ae7169cd14ea0eabf8e536f2269 144B
4bfe325ff21064617f64834a0a9f274cc5f869 825B
4eab05bd28e8d80808cc22a2896ce8667f87ce 155B
4fdfed6ffa6fd530d0e34f38f92f4864e8585b 305B
513583f39de3e03f8365b435333b270dc6921a 242B
5255b74bc135108bc228dd7a8921be122a6771 1KB
52997059ed9da4049dda79faaaa73b4cfa30be 381KB
58a96b70cfba9466bacca19c0d99b87cf53734 55KB
59d82d11859dec676493b763fecb50a49f4aa8 4KB
5e0f4732394cc499594f314bed4a2241d77460 611B
5f1388782c8d55db2558258d376050f02c7fa5 220B
60ad7b1b379b923693ab1db91e4470e294d20f 804B
60f3556376a0a4d589a0897f0e2c42ccf670da 2KB
621045493c9c2c9bff1e4a713ec9662f9f2078 100B
641af2b3850a8887660971e69b3a6907105ea9 54B
648fa27b9f976528d397aa8ba7c56e485cb581 983B
662ec3ba7f9f056c09e94fee14662f00c47ed6 561B
67e717565a53bdc8e5748bf2d39146ee280c54 92B
685f10c0c621a94384e549f61f7265a13f645e 207KB
6cc34d30e22ad05a2feacd903f730fb53237c4 2KB
6e5ca626f5b21a4e6ba5838964b3f788a9aec7 229B
6ec990a44e989f472c38b93213ababad675c0b 798B
72fb1ee933df24c332b3373fb4c52c9c3c14a4 864B
73530c4b1d4a9dd167affdc44af77cd8398aad 379B
745b6113590e720c0a6e3935beccfd2b0cf48b 318B
74f951dad3ee8a71317afa0181018dfa5b6f85 479B
78945c97e027248e1bc7fa7c042051995232b5 384B
7aaba054339dfd48c13727ca4e34688237c0b7 55B
7dec162a585ea6b0c1f8359051c5464c16487a 285B
7e1dfea9b6c04bd369e0ea501a59c12d829dbd 424B
7f08a6581dd2bc3d8494800fd65547ebd5ff3d 295B
7f2b72da9374ab9bb13243b59950f602bdbb62 491B
7f60cd7f3dfc776ba73b6226b764343d9be3da 225B
7fc266c3e32283a2b21fe12166ebdcc33a1da1 274KB
810ca969c361d1eaaa3237c647e420e2469892 520B
8645304733cbe3fa7156495e5a016f9840839f 85B
86bba9f0f5f8821de6ba187d79ec3cf91a66ed 881B
8938e0b6de3b64f294ae2260513f0f983cc90a 64B
897cb759a98e7571770a6952f94679af0a5992 342B
8bafc46e1b20e1fd4964edb3331ede157ac254 420B
8dd4965cbcd87710004015f34454f823f917c8 694B
8e46fb7b1538bec29a99c3ebea6337ae03596c 224B
8e835774394b8bfa817c96bbfac1a84da126c8 173KB
8f11859216db8d97ce30a67f8522a6f2d7e78c 82B
8f769c40cb0a834e6d12ba04d4792521c9a869 176B
90b5d0305b7e61c00070e8616911a82ba0e8b6 698B
93d54639be70ba99f477f5e5d3a2473b914217 453B
944f929e3f3e9e0287e6124bdd65747aeda54f 174B
94b9efbe54b721a4eef8e72c56b06c1b057c16 330B
94fbb26dcaafa4618200c44f55125912041707 603B
95221383fb264cc582aca224c13dbecbfecc7e 259KB
973881f4a854d5c8d2592bdc362f91a0ab9b8d 84B
982ca3e576810e3ff064d8b3a3b19535436b9a 498B
9e74e4b3eede8f288be4e25309805425fc359f 888B
9fc3ff92668d85055f1e9644da43c6ab1a9989 413B
a1f480bde77fcc684e9a69f45d47c8566875bf 720B
a97dfceefc4128df6a491788817d546a27e83a 197B
ab0f30e98653d5d894f4a1ca3e66c4f973e989 333B
ad06c5acaad09ee4d6e9d7c428506db028aeeb 38KB
b340b37e1d3b3ae2831df462e6a7dd347ce48e 367B
b4b1964444f62d65754e0937d5ab53eae3f03e 89B
code.bmp 9KB
c191abed36f0b1cf75cae8654ee9891e39ee61 372B
c6583a1eb35c440f166b90a54eb8103b23cc5a 1KB
c8c9942ec0e62df9708ba9b44ea96631b4a9c9 54B
c92098efc1d287b1e421a51d0f08e43e88e8e9 437B
cb7a518634c10aa76af874bb3ab026ea4f7653 44B
cff2b0a6bbcdbe72b6999e28aad302377727f3 180B
COMMIT_EDITMSG 91B
config 405B
style.css 4KB
d258341bf7388b2280a624a942dd56c569e716 449B
d5df218e89d125acc228daf49ac0bdfccc394e 1KB
d618329f8f3a2ef4f9ae62444286829513f220 763B
d7f844e577f9e8fff9a392ed7bd301260bbdca 508B
d86cf5b9d6f55ab05907f984e71d16b6642db1 300B
d9086da919957d12f067e7c29f703c962e3d83 4KB
d986275d94a72ae1c674a322105a2456b1fbfb 147B
共 221 条
- 1
- 2
- 3
代码世界观
- 粉丝: 7
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0