步骤 2 : 模仿和排错 步骤 3 : 购物车页面操作 步骤 4 : 调整订单数量 步骤 5 : 删除订单项 步骤 6 : 提交到结算页面
增值内容,请先登录
完整的J2EE模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE一整套技术栈, 从无到有涵盖全部147个知识点,475个开发步骤, 充实J2EE项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的J2EE模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE一整套技术栈, 从无到有涵盖全部147个知识点,475个开发步骤, 充实J2EE项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的J2EE模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE一整套技术栈, 从无到有涵盖全部147个知识点,475个开发步骤, 充实J2EE项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的J2EE模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE一整套技术栈, 从无到有涵盖全部147个知识点,475个开发步骤, 充实J2EE项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
var page = "forechangeOrderItem";
$.post(
page,
{"pid":pid,"number":num},
function(result){
if("success"!=result){
location.href="login.jsp";
}
}
);
public String changeOrderItem(HttpServletRequest request, HttpServletResponse response, Page page) {
User user =(User) request.getSession().getAttribute("user");
if(null==user)
return "%fail";
int pid = Integer.parseInt(request.getParameter("pid"));
int number = Integer.parseInt(request.getParameter("number"));
List<OrderItem> ois = orderItemDAO.listByUser(user.getId());
for (OrderItem oi : ois) {
if(oi.getProduct().getId()==pid){
oi.setNumber(number);
orderItemDAO.update(oi);
break;
}
}
return "%success";
}
package tmall.servlet;
import java.io.BufferedWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.util.HtmlUtils;
import tmall.bean.Category;
import tmall.bean.OrderItem;
import tmall.bean.Product;
import tmall.bean.ProductImage;
import tmall.bean.PropertyValue;
import tmall.bean.Review;
import tmall.bean.User;
import tmall.comparator.ProductAllComparator;
import tmall.comparator.ProductDateComparator;
import tmall.comparator.ProductPriceComparator;
import tmall.comparator.ProductReviewComparator;
import tmall.comparator.ProductSaleCountComparator;
import tmall.dao.CategoryDAO;
import tmall.dao.ProductDAO;
import tmall.dao.ProductImageDAO;
import tmall.util.Page;
public class ForeServlet extends BaseForeServlet {
public String home(HttpServletRequest request, HttpServletResponse response, Page page) {
List<Category> cs= new CategoryDAO().list();
new ProductDAO().fill(cs);
new ProductDAO().fillByRow(cs);
request.setAttribute("cs", cs);
return "home.jsp";
}
public String register(HttpServletRequest request, HttpServletResponse response, Page page) {
String name = request.getParameter("name");
String password = request.getParameter("password");
name = HtmlUtils.htmlEscape(name);
System.out.println(name);
boolean exist = userDAO.isExist(name);
if(exist){
request.setAttribute("msg", "用户名已经被使用,不能使用");
return "register.jsp";
}
User user = new User();
user.setName(name);
user.setPassword(password);
System.out.println(user.getName());
System.out.println(user.getPassword());
userDAO.add(user);
return "@registerSuccess.jsp";
}
public String login(HttpServletRequest request, HttpServletResponse response, Page page) {
String name = request.getParameter("name");
name = HtmlUtils.htmlEscape(name);
String password = request.getParameter("password");
User user = userDAO.get(name,password);
if(null==user){
request.setAttribute("msg", "账号密码错误");
return "login.jsp";
}
request.getSession().setAttribute("user", user);
return "@forehome";
}
public String product(HttpServletRequest request, HttpServletResponse response, Page page) {
int pid = Integer.parseInt(request.getParameter("pid"));
Product p = productDAO.get(pid);
List<ProductImage> productSingleImages = productImageDAO.list(p, ProductImageDAO.type_single);
List<ProductImage> productDetailImages = productImageDAO.list(p, ProductImageDAO.type_detail);
p.setProductSingleImages(productSingleImages);
p.setProductDetailImages(productDetailImages);
List<PropertyValue> pvs = propertyValueDAO.list(p.getId());
List<Review> reviews = reviewDAO.list(p.getId());
productDAO.setSaleAndReviewNumber(p);
request.setAttribute("reviews", reviews);
request.setAttribute("p", p);
request.setAttribute("pvs", pvs);
return "product.jsp";
}
public String logout(HttpServletRequest request, HttpServletResponse response, Page page) {
request.getSession().removeAttribute("user");
return "@forehome";
}
public String checkLogin(HttpServletRequest request, HttpServletResponse response, Page page) {
User user =(User) request.getSession().getAttribute("user");
if(null!=user)
return "%success";
return "%fail";
}
public String loginAjax(HttpServletRequest request, HttpServletResponse response, Page page) {
String name = request.getParameter("name");
String password = request.getParameter("password");
User user = userDAO.get(name,password);
if(null==user){
return "%fail";
}
request.getSession().setAttribute("user", user);
return "%success";
}
public String category(HttpServletRequest request, HttpServletResponse response, Page page) {
int cid = Integer.parseInt(request.getParameter("cid"));
Category c = new CategoryDAO().get(cid);
new ProductDAO().fill(c);
new ProductDAO().setSaleAndReviewNumber(c.getProducts());
String sort = request.getParameter("sort");
if(null!=sort){
switch(sort){
case "review":
Collections.sort(c.getProducts(),new ProductReviewComparator());
break;
case "date" :
Collections.sort(c.getProducts(),new ProductDateComparator());
break;
case "saleCount" :
Collections.sort(c.getProducts(),new ProductSaleCountComparator());
break;
case "price":
Collections.sort(c.getProducts(),new ProductPriceComparator());
break;
case "all":
Collections.sort(c.getProducts(),new ProductAllComparator());
break;
}
}
request.setAttribute("c", c);
return "category.jsp";
}
public String search(HttpServletRequest request, HttpServletResponse response, Page page){
String keyword = request.getParameter("keyword");
List<Product> ps= new ProductDAO().search(keyword,0,20);
productDAO.setSaleAndReviewNumber(ps);
request.setAttribute("ps",ps);
return "searchResult.jsp";
}
public String buyone(HttpServletRequest request, HttpServletResponse response, Page page) {
int pid = Integer.parseInt(request.getParameter("pid"));
int num = Integer.parseInt(request.getParameter("num"));
Product p = productDAO.get(pid);
int oiid = 0;
User user =(User) request.getSession().getAttribute("user");
boolean found = false;
List<OrderItem> ois = orderItemDAO.listByUser(user.getId());
for (OrderItem oi : ois) {
if(oi.getProduct().getId()==p.getId()){
oi.setNumber(oi.getNumber()+num);
orderItemDAO.update(oi);
found = true;
oiid = oi.getId();
break;
}
}
if(!found){
OrderItem oi = new OrderItem();
oi.setUser(user);
oi.setNumber(num);
oi.setProduct(p);
orderItemDAO.add(oi);
oiid = oi.getId();
}
return "@forebuy?oiid="+oiid;
}
public String buy(HttpServletRequest request, HttpServletResponse response, Page page){
String[] oiids=request.getParameterValues("oiid");
List<OrderItem> ois = new ArrayList<>();
float total = 0;
for (String strid : oiids) {
int oiid = Integer.parseInt(strid);
OrderItem oi= orderItemDAO.get(oiid);
total +=oi.getProduct().getPromotePrice()*oi.getNumber();
ois.add(oi);
}
request.getSession().setAttribute("ois", ois);
request.setAttribute("total", total);
return "buy.jsp";
}
public String addCart(HttpServletRequest request, HttpServletResponse response, Page page) {
int pid = Integer.parseInt(request.getParameter("pid"));
Product p = productDAO.get(pid);
int num = Integer.parseInt(request.getParameter("num"));
User user =(User) request.getSession().getAttribute("user");
boolean found = false;
List<OrderItem> ois = orderItemDAO.listByUser(user.getId());
for (OrderItem oi : ois) {
if(oi.getProduct().getId()==p.getId()){
oi.setNumber(oi.getNumber()+num);
orderItemDAO.update(oi);
found = true;
break;
}
}
if(!found){
OrderItem oi = new OrderItem();
oi.setUser(user);
oi.setNumber(num);
oi.setProduct(p);
orderItemDAO.add(oi);
}
return "%success";
}
public String cart(HttpServletRequest request, HttpServletResponse response, Page page) {
User user =(User) request.getSession().getAttribute("user");
List<OrderItem> ois = orderItemDAO.listByUser(user.getId());
request.setAttribute("ois", ois);
return "cart.jsp";
}
public String changeOrderItem(HttpServletRequest request, HttpServletResponse response, Page page) {
User user =(User) request.getSession().getAttribute("user");
if(null==user)
return "%fail";
int pid = Integer.parseInt(request.getParameter("pid"));
int number = Integer.parseInt(request.getParameter("number"));
List<OrderItem> ois = orderItemDAO.listByUser(user.getId());
for (OrderItem oi : ois) {
if(oi.getProduct().getId()==pid){
oi.setNumber(number);
orderItemDAO.update(oi);
break;
}
}
return "%success";
}
}
增值内容,请先登录
完整的J2EE模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE一整套技术栈, 从无到有涵盖全部147个知识点,475个开发步骤, 充实J2EE项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
var page="foredeleteOrderItem";
$.post(
page,
{"oiid":deleteOrderItemid},
function(result){
if("success"==result){
$("tr.cartProductItemTR[oiid="+deleteOrderItemid+"]").hide();
}
else{
location.href="login.jsp";
}
}
);
public String deleteOrderItem(HttpServletRequest request, HttpServletResponse response, Page page){
User user =(User) request.getSession().getAttribute("user");
if(null==user)
return "%fail";
int oiid = Integer.parseInt(request.getParameter("oiid"));
orderItemDAO.delete(oiid);
return "%success";
}
package tmall.servlet;
import java.io.BufferedWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.util.HtmlUtils;
import tmall.bean.Category;
import tmall.bean.OrderItem;
import tmall.bean.Product;
import tmall.bean.ProductImage;
import tmall.bean.PropertyValue;
import tmall.bean.Review;
import tmall.bean.User;
import tmall.comparator.ProductAllComparator;
import tmall.comparator.ProductDateComparator;
import tmall.comparator.ProductPriceComparator;
import tmall.comparator.ProductReviewComparator;
import tmall.comparator.ProductSaleCountComparator;
import tmall.dao.CategoryDAO;
import tmall.dao.ProductDAO;
import tmall.dao.ProductImageDAO;
import tmall.util.Page;
public class ForeServlet extends BaseForeServlet {
public String home(HttpServletRequest request, HttpServletResponse response, Page page) {
List<Category> cs= new CategoryDAO().list();
new ProductDAO().fill(cs);
new ProductDAO().fillByRow(cs);
request.setAttribute("cs", cs);
return "home.jsp";
}
public String register(HttpServletRequest request, HttpServletResponse response, Page page) {
String name = request.getParameter("name");
String password = request.getParameter("password");
name = HtmlUtils.htmlEscape(name);
System.out.println(name);
boolean exist = userDAO.isExist(name);
if(exist){
request.setAttribute("msg", "用户名已经被使用,不能使用");
return "register.jsp";
}
User user = new User();
user.setName(name);
user.setPassword(password);
System.out.println(user.getName());
System.out.println(user.getPassword());
userDAO.add(user);
return "@registerSuccess.jsp";
}
public String login(HttpServletRequest request, HttpServletResponse response, Page page) {
String name = request.getParameter("name");
name = HtmlUtils.htmlEscape(name);
String password = request.getParameter("password");
User user = userDAO.get(name,password);
if(null==user){
request.setAttribute("msg", "账号密码错误");
return "login.jsp";
}
request.getSession().setAttribute("user", user);
return "@forehome";
}
public String product(HttpServletRequest request, HttpServletResponse response, Page page) {
int pid = Integer.parseInt(request.getParameter("pid"));
Product p = productDAO.get(pid);
List<ProductImage> productSingleImages = productImageDAO.list(p, ProductImageDAO.type_single);
List<ProductImage> productDetailImages = productImageDAO.list(p, ProductImageDAO.type_detail);
p.setProductSingleImages(productSingleImages);
p.setProductDetailImages(productDetailImages);
List<PropertyValue> pvs = propertyValueDAO.list(p.getId());
List<Review> reviews = reviewDAO.list(p.getId());
productDAO.setSaleAndReviewNumber(p);
request.setAttribute("reviews", reviews);
request.setAttribute("p", p);
request.setAttribute("pvs", pvs);
return "product.jsp";
}
public String logout(HttpServletRequest request, HttpServletResponse response, Page page) {
request.getSession().removeAttribute("user");
return "@forehome";
}
public String checkLogin(HttpServletRequest request, HttpServletResponse response, Page page) {
User user =(User) request.getSession().getAttribute("user");
if(null!=user)
return "%success";
return "%fail";
}
public String loginAjax(HttpServletRequest request, HttpServletResponse response, Page page) {
String name = request.getParameter("name");
String password = request.getParameter("password");
User user = userDAO.get(name,password);
if(null==user){
return "%fail";
}
request.getSession().setAttribute("user", user);
return "%success";
}
public String category(HttpServletRequest request, HttpServletResponse response, Page page) {
int cid = Integer.parseInt(request.getParameter("cid"));
Category c = new CategoryDAO().get(cid);
new ProductDAO().fill(c);
new ProductDAO().setSaleAndReviewNumber(c.getProducts());
String sort = request.getParameter("sort");
if(null!=sort){
switch(sort){
case "review":
Collections.sort(c.getProducts(),new ProductReviewComparator());
break;
case "date" :
Collections.sort(c.getProducts(),new ProductDateComparator());
break;
case "saleCount" :
Collections.sort(c.getProducts(),new ProductSaleCountComparator());
break;
case "price":
Collections.sort(c.getProducts(),new ProductPriceComparator());
break;
case "all":
Collections.sort(c.getProducts(),new ProductAllComparator());
break;
}
}
request.setAttribute("c", c);
return "category.jsp";
}
public String search(HttpServletRequest request, HttpServletResponse response, Page page){
String keyword = request.getParameter("keyword");
List<Product> ps= new ProductDAO().search(keyword,0,20);
productDAO.setSaleAndReviewNumber(ps);
request.setAttribute("ps",ps);
return "searchResult.jsp";
}
public String buyone(HttpServletRequest request, HttpServletResponse response, Page page) {
int pid = Integer.parseInt(request.getParameter("pid"));
int num = Integer.parseInt(request.getParameter("num"));
Product p = productDAO.get(pid);
int oiid = 0;
User user =(User) request.getSession().getAttribute("user");
boolean found = false;
List<OrderItem> ois = orderItemDAO.listByUser(user.getId());
for (OrderItem oi : ois) {
if(oi.getProduct().getId()==p.getId()){
oi.setNumber(oi.getNumber()+num);
orderItemDAO.update(oi);
found = true;
oiid = oi.getId();
break;
}
}
if(!found){
OrderItem oi = new OrderItem();
oi.setUser(user);
oi.setNumber(num);
oi.setProduct(p);
orderItemDAO.add(oi);
oiid = oi.getId();
}
return "@forebuy?oiid="+oiid;
}
public String buy(HttpServletRequest request, HttpServletResponse response, Page page){
String[] oiids=request.getParameterValues("oiid");
List<OrderItem> ois = new ArrayList<>();
float total = 0;
for (String strid : oiids) {
int oiid = Integer.parseInt(strid);
OrderItem oi= orderItemDAO.get(oiid);
total +=oi.getProduct().getPromotePrice()*oi.getNumber();
ois.add(oi);
}
request.getSession().setAttribute("ois", ois);
request.setAttribute("total", total);
return "buy.jsp";
}
public String addCart(HttpServletRequest request, HttpServletResponse response, Page page) {
int pid = Integer.parseInt(request.getParameter("pid"));
Product p = productDAO.get(pid);
int num = Integer.parseInt(request.getParameter("num"));
User user =(User) request.getSession().getAttribute("user");
boolean found = false;
List<OrderItem> ois = orderItemDAO.listByUser(user.getId());
for (OrderItem oi : ois) {
if(oi.getProduct().getId()==p.getId()){
oi.setNumber(oi.getNumber()+num);
orderItemDAO.update(oi);
found = true;
break;
}
}
if(!found){
OrderItem oi = new OrderItem();
oi.setUser(user);
oi.setNumber(num);
oi.setProduct(p);
orderItemDAO.add(oi);
}
return "%success";
}
public String cart(HttpServletRequest request, HttpServletResponse response, Page page) {
User user =(User) request.getSession().getAttribute("user");
List<OrderItem> ois = orderItemDAO.listByUser(user.getId());
request.setAttribute("ois", ois);
return "cart.jsp";
}
public String changeOrderItem(HttpServletRequest request, HttpServletResponse response, Page page) {
User user =(User) request.getSession().getAttribute("user");
if(null==user)
return "%fail";
int pid = Integer.parseInt(request.getParameter("pid"));
int number = Integer.parseInt(request.getParameter("number"));
List<OrderItem> ois = orderItemDAO.listByUser(user.getId());
for (OrderItem oi : ois) {
if(oi.getProduct().getId()==pid){
oi.setNumber(number);
orderItemDAO.update(oi);
break;
}
}
return "%success";
}
public String deleteOrderItem(HttpServletRequest request, HttpServletResponse response, Page page){
User user =(User) request.getSession().getAttribute("user");
if(null==user)
return "%fail";
int oiid = Integer.parseInt(request.getParameter("oiid"));
orderItemDAO.delete(oiid);
return "%success";
}
}
增值内容,请先登录
完整的J2EE模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE一整套技术栈, 从无到有涵盖全部147个知识点,475个开发步骤, 充实J2EE项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。
问答区域
2021-01-25
deleteOrderItem,根据ooid删除购物车产品,那我登陆状态下,输入别人购物车的oiid也可以删除别人购物车的产品啊
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
2019-12-20
当我把删除按钮上的oiid属性去掉后的一个疑问
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
2019-10-22
删除订单项后,页面上对应的订单项仅仅是被隐藏而不是真正删除的问题等
2019-04-27
bug
2018-12-01
关于 changeOrderItem 问题
提问太多,页面渲染太慢,为了加快渲染速度,本页最多只显示几条提问。还有 5 条以前的提问,请 点击查看
提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
|