步骤 2 : 模仿和排错 步骤 3 : 结算页操作 步骤 4 : 运行效果 步骤 5 : ForeServlet.createOrder 步骤 6 : 确认支付页 步骤 7 : 支付成功页
增值内容,请先登录
完整的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项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的J2EE模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE一整套技术栈, 从无到有涵盖全部147个知识点,475个开发步骤, 充实J2EE项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
public String createOrder(HttpServletRequest request, HttpServletResponse response, Page page){
User user =(User) request.getSession().getAttribute("user");
List<OrderItem> ois= (List<OrderItem>) request.getSession().getAttribute("ois");
if(ois.isEmpty())
return "@login.jsp";
String address = request.getParameter("address");
String post = request.getParameter("post");
String receiver = request.getParameter("receiver");
String mobile = request.getParameter("mobile");
String userMessage = request.getParameter("userMessage");
Order order = new Order();
String orderCode = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) +RandomUtils.nextInt(10000);
order.setOrderCode(orderCode);
order.setAddress(address);
order.setPost(post);
order.setReceiver(receiver);
order.setMobile(mobile);
order.setUserMessage(userMessage);
order.setCreateDate(new Date());
order.setUser(user);
order.setStatus(OrderDAO.waitPay);
orderDAO.add(order);
float total =0;
for (OrderItem oi: ois) {
oi.setOrder(order);
orderItemDAO.update(oi);
total+=oi.getProduct().getPromotePrice()*oi.getNumber();
}
return "@forealipay?oid="+order.getId() +"&total="+total;
}
package tmall.servlet;
import java.io.BufferedWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.math.RandomUtils;
import org.springframework.web.util.HtmlUtils;
import tmall.bean.Category;
import tmall.bean.Order;
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.OrderDAO;
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";
}
public String createOrder(HttpServletRequest request, HttpServletResponse response, Page page){
User user =(User) request.getSession().getAttribute("user");
List<OrderItem> ois= (List<OrderItem>) request.getSession().getAttribute("ois");
if(ois.isEmpty())
return "@login.jsp";
String address = request.getParameter("address");
String post = request.getParameter("post");
String receiver = request.getParameter("receiver");
String mobile = request.getParameter("mobile");
String userMessage = request.getParameter("userMessage");
Order order = new Order();
String orderCode = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) +RandomUtils.nextInt(10000);
order.setOrderCode(orderCode);
order.setAddress(address);
order.setPost(post);
order.setReceiver(receiver);
order.setMobile(mobile);
order.setUserMessage(userMessage);
order.setCreateDate(new Date());
order.setUser(user);
order.setStatus(OrderDAO.waitPay);
orderDAO.add(order);
float total =0;
for (OrderItem oi: ois) {
oi.setOrder(order);
orderItemDAO.update(oi);
total+=oi.getProduct().getPromotePrice()*oi.getNumber();
}
return "@forealipay?oid="+order.getId() +"&total="+total;
}
public String alipay(HttpServletRequest request, HttpServletResponse response, Page page){
return "alipay.jsp";
}
public String payed(HttpServletRequest request, HttpServletResponse response, Page page) {
int oid = Integer.parseInt(request.getParameter("oid"));
Order order = orderDAO.get(oid);
order.setStatus(OrderDAO.waitDelivery);
order.setPayDate(new Date());
new OrderDAO().update(order);
request.setAttribute("o", order);
return "payed.jsp";
}
}
增值内容,请先登录
完整的J2EE模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE一整套技术栈, 从无到有涵盖全部147个知识点,475个开发步骤, 充实J2EE项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
public String alipay(HttpServletRequest request, HttpServletResponse response, Page page){
return "alipay.jsp";
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<%@include file="include/header.jsp"%>
<%@include file="include/top.jsp"%>
<%@include file="include/cart/alipayPage.jsp"%>
<%@include file="include/footer.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<div class="aliPayPageDiv">
<div class="aliPayPageLogo">
<img class="pull-left" src="img/site/simpleLogo.png">
<div style="clear:both"></div>
</div>
<div>
<span class="confirmMoneyText">扫一扫付款(元)</span>
<span class="confirmMoney">
¥<fmt:formatNumber type="number" value="${param.total}" minFractionDigits="2"/></span>
</div>
<div>
<img class="aliPayImg" src="img/site/alipay2wei.png">
</div>
<div>
<a href="forepayed?oid=${param.oid}&total=${param.total}"><button class="confirmPay">确认支付</button></a>
</div>
</div>
package tmall.servlet;
import java.io.BufferedWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.math.RandomUtils;
import org.springframework.web.util.HtmlUtils;
import tmall.bean.Category;
import tmall.bean.Order;
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.OrderDAO;
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";
}
public String createOrder(HttpServletRequest request, HttpServletResponse response, Page page){
User user =(User) request.getSession().getAttribute("user");
String address = request.getParameter("address");
String post = request.getParameter("post");
String receiver = request.getParameter("receiver");
String mobile = request.getParameter("mobile");
String userMessage = request.getParameter("userMessage");
String orderCode = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) +RandomUtils.nextInt(10000);
Order order = new Order();
order.setOrderCode(orderCode);
order.setAddress(address);
order.setPost(post);
order.setReceiver(receiver);
order.setMobile(mobile);
order.setUserMessage(userMessage);
order.setCreateDate(new Date());
order.setUser(user);
order.setStatus(OrderDAO.waitPay);
orderDAO.add(order);
List<OrderItem> ois= (List<OrderItem>) request.getSession().getAttribute("ois");
float total =0;
for (OrderItem oi: ois) {
oi.setOrder(order);
orderItemDAO.update(oi);
total+=oi.getProduct().getPromotePrice()*oi.getNumber();
}
return "@forealipay?oid="+order.getId() +"&total="+total;
}
public String alipay(HttpServletRequest request, HttpServletResponse response, Page page){
return "alipay.jsp";
}
public String payed(HttpServletRequest request, HttpServletResponse response, Page page) {
int oid = Integer.parseInt(request.getParameter("oid"));
Order order = orderDAO.get(oid);
order.setStatus(OrderDAO.waitDelivery);
order.setPayDate(new Date());
new OrderDAO().update(order);
request.setAttribute("o", order);
return "payed.jsp";
}
}
增值内容,请先登录
完整的J2EE模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE一整套技术栈, 从无到有涵盖全部147个知识点,475个开发步骤, 充实J2EE项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
public String payed(HttpServletRequest request, HttpServletResponse response, Page page) {
int oid = Integer.parseInt(request.getParameter("oid"));
Order order = orderDAO.get(oid);
order.setStatus(OrderDAO.waitDelivery);
order.setPayDate(new Date());
new OrderDAO().update(order);
request.setAttribute("o", order);
return "payed.jsp";
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<%@include file="include/header.jsp"%>
<%@include file="include/top.jsp"%>
<%@include file="include/simpleSearch.jsp"%>
<%@include file="include/cart/payedPage.jsp"%>
<%@include file="include/footer.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<div class="payedDiv">
<div class="payedTextDiv">
<img src="img/site/paySuccess.png">
<span>您已成功付款</span>
</div>
<div class="payedAddressInfo">
<ul>
<li>收货地址:${o.address} ${o.receiver} ${o.mobile }</li>
<li>实付款:<span class="payedInfoPrice">
¥<fmt:formatNumber type="number" value="${param.total}" minFractionDigits="2"/>
</li>
<li>预计08月08日送达 </li>
</ul>
<div class="paedCheckLinkDiv">
您可以
<a class="payedCheckLink" href="forebought">查看已买到的宝贝</a>
<a class="payedCheckLink" href="forebought">查看交易详情 </a>
</div>
</div>
<div class="payedSeperateLine">
</div>
<div class="warningDiv">
<img src="img/site/warning.png">
<b>安全提醒:</b>下单后,<span class="redColor boldWord">用QQ给您发送链接办理退款的都是骗子!</span>天猫不存在系统升级,订单异常等问题,谨防假冒客服电话诈骗!
</div>
</div>
package tmall.servlet;
import java.io.BufferedWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.math.RandomUtils;
import org.springframework.web.util.HtmlUtils;
import tmall.bean.Category;
import tmall.bean.Order;
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.OrderDAO;
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";
}
public String createOrder(HttpServletRequest request, HttpServletResponse response, Page page){
User user =(User) request.getSession().getAttribute("user");
String address = request.getParameter("address");
String post = request.getParameter("post");
String receiver = request.getParameter("receiver");
String mobile = request.getParameter("mobile");
String userMessage = request.getParameter("userMessage");
String orderCode = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) +RandomUtils.nextInt(10000);
Order order = new Order();
order.setOrderCode(orderCode);
order.setAddress(address);
order.setPost(post);
order.setReceiver(receiver);
order.setMobile(mobile);
order.setUserMessage(userMessage);
order.setCreateDate(new Date());
order.setUser(user);
order.setStatus(OrderDAO.waitPay);
orderDAO.add(order);
List<OrderItem> ois= (List<OrderItem>) request.getSession().getAttribute("ois");
float total =0;
for (OrderItem oi: ois) {
oi.setOrder(order);
orderItemDAO.update(oi);
total+=oi.getProduct().getPromotePrice()*oi.getNumber();
}
return "@forealipay?oid="+order.getId() +"&total="+total;
}
public String alipay(HttpServletRequest request, HttpServletResponse response, Page page){
return "alipay.jsp";
}
public String payed(HttpServletRequest request, HttpServletResponse response, Page page) {
int oid = Integer.parseInt(request.getParameter("oid"));
Order order = orderDAO.get(oid);
order.setStatus(OrderDAO.waitDelivery);
order.setPayDate(new Date());
new OrderDAO().update(order);
request.setAttribute("o", order);
return "payed.jsp";
}
}
HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。
问答区域
2021-05-17
服务器错误500
2 个答案
lzqcdlxhy 跳转到问题位置 答案时间:2023-05-07 老哥,你数据库用的是不是mysql8.0的版本。我把8.0卸载换成站长的版本,再点击支付页面就没有500的报错了,而且没换之前点击 ‘立即购买’ 也有bug,第一次点报错,返回再点击‘立即购买’就出现订单页面了。排查了好久。。。
how2j 跳转到问题位置 答案时间:2021-06-05 根据报错你的OrderDAO 第95行报错空指针异常,看看具体是什么数据没有导致的呢?
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
2020-04-25
total值
4 个答案
Lz2848509 跳转到问题位置 答案时间:2020-04-27 是的 我还有一个问题是List<OrderItem> ois= (List<OrderItem>) request.getSession().getAttribute("ois");
为什么可以从session获取ois 我们之前好像并没有把他存到session里去
how2j 跳转到问题位置 答案时间:2020-04-26 payedInfoPrice 这个貌似忘记写 </span> 收尾了
how2j 跳转到问题位置 答案时间:2020-04-26 后面跟了参数就可以传递过去了。
Lz2848509 跳转到问题位置 答案时间:2020-04-25 同时好像实付款里的 span.payedInfoPrice 没有/span
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
2019-11-09
支付是如何实现的
2019-08-20
session过期与实效区别
2019-07-12
关于从session中获取订单项集合
提问太多,页面渲染太慢,为了加快渲染速度,本页最多只显示几条提问。还有 9 条以前的提问,请 点击查看
提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
|