/**
* 模仿天猫整站j2ee 教程 为how2j.cn 版权所有
* 本教程仅用于学习使用,切勿用于非法用途,由此引起一切后果与本站无关
* 供购买者学习,请勿私自传播,否则自行承担相关法律责任
*/
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().getAttr
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
使用 J2EE 技术开发的模仿天猫商城,具备前端、后台功能。1. MVC 设计模式 2. Filter+Servlet+反射 3. 统一的分页查询简化开发 4. 模块化JSP设计.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
资源推荐
资源详情
资源评论
收起资源包目录
使用 J2EE 技术开发的模仿天猫商城,具备前端、后台功能。(毕设&课设&实训&大作业&竞赛&项目) (2000个子文件)
ForeServlet.class 13KB
ProductDAO.class 12KB
OrderItemDAO.class 10KB
OrderDAO.class 9KB
PropertyValueDAO.class 8KB
ReviewDAO.class 8KB
UserDAO.class 7KB
PropertyDAO.class 6KB
ProductImageServlet.class 6KB
ProductImageDAO.class 6KB
BaseBackServlet.class 6KB
CategoryServlet.class 5KB
CategoryDAO.class 5KB
ProductServlet.class 4KB
Order.class 4KB
Product.class 4KB
ForeServletFilter.class 3KB
BaseForeServlet.class 3KB
PropertyServlet.class 3KB
ImageUtil.class 3KB
ForeAuthFilter.class 3KB
BackServletFilter.class 3KB
Test.class 2KB
OrderServlet.class 2KB
Category.class 2KB
DBUtil.class 2KB
Page.class 2KB
UserServlet.class 2KB
User.class 1KB
Review.class 1KB
OrderItem.class 1KB
EncodingFilter.class 1KB
PropertyValue.class 1KB
ProductImage.class 991B
Property.class 985B
ProductDateComparator.class 858B
ProductAllComparator.class 810B
ProductSaleCountComparator.class 791B
ProductReviewComparator.class 784B
ProductPriceComparator.class 783B
DateUtil.class 710B
.classpath 979B
bootstrap.css 143KB
bootstrap.min.css 118KB
style.css 35KB
bootstrap-theme.css 26KB
bootstrap-theme.min.css 23KB
style.css 1KB
logo.gif 77KB
wangwang.gif 4KB
spring-web-3.2.0.M1.jar 561KB
mysql-connector-java-5.0.8-bin.jar 528KB
spring-core-3.2.0.M1.jar 440KB
standard.jar 287KB
commons-lang-2.5.jar 273KB
servlet-api.jar 193KB
commons-io-1.4.jar 106KB
commons-fileupload-1.2.2.jar 58KB
jstl.jar 17KB
ForeServlet.java 13KB
ProductDAO.java 11KB
OrderDAO.java 10KB
OrderItemDAO.java 9KB
PropertyValueDAO.java 7KB
ReviewDAO.java 7KB
UserDAO.java 6KB
ProductImageServlet.java 5KB
PropertyDAO.java 5KB
BaseBackServlet.java 5KB
ProductServlet.java 4KB
ProductImageDAO.java 4KB
CategoryServlet.java 4KB
CategoryDAO.java 4KB
Order.java 3KB
Product.java 3KB
PropertyServlet.java 3KB
ImageUtil.java 3KB
BaseForeServlet.java 3KB
ForeServletFilter.java 2KB
ForeAuthFilter.java 2KB
Test.java 2KB
Page.java 2KB
OrderServlet.java 2KB
BackServletFilter.java 2KB
UserServlet.java 2KB
EncodingFilter.java 1KB
DBUtil.java 1KB
Category.java 1KB
Review.java 1KB
User.java 1KB
OrderItem.java 1KB
PropertyValue.java 1KB
Property.java 940B
ProductImage.java 935B
DateUtil.java 823B
ProductAllComparator.java 799B
ProductPriceComparator.java 775B
ProductDateComparator.java 773B
ProductReviewComparator.java 766B
ProductSaleCountComparator.java 765B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
热爱技术。
- 粉丝: 2473
- 资源: 7862
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- OpenSSL-3.2.1.tar.gz
- 2024年下半年软考中级网络工程师radius配置思路
- 基于Python+Vue实现的中医智能舌诊系统源代码+数据库+文档说明(深度学习对舌象的舌色、舌苔色、薄厚、腻否四维分类)
- 柯尼卡美能达Bizhub C364e打印机驱动下载
- 基于Python+Vue实现的中医智能舌诊系统源代码+数据库+文档说明(毕业设计)
- 【Unity行为树插件扩展包】Behavior Designer - Movement Pack
- Java使用Poi导出PPT幻灯片java-poi
- 定制红米10X-5G版miui14-fast线刷 去账号锁 解锁bl后fast刷写
- 多分类模型软/硬投票预测代码
- C++《混合A星算法的路径规划》+项目源码+文档说明+代码注释
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功