package servlet;
import bean.*;
import comparator.*;
import dao.CategoryDAO;
import dao.OrderDAO;
import dao.ProductDAO;
import dao.ProductImageDAO;
import util.Page;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.*;
public class ForeServlet extends BaseForeServlet {
/**
* 显示主页
*
* @param request
* @param response
* @param page
* @return
*/
public String home(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了 ForeServlet home方法");
List<Category> cs = new CategoryDAO().list();
new ProductDAO().fill(cs);
new ProductDAO().fillByRow(cs);
request.setAttribute("cs", cs);
return "home.jsp";
}
/**
* 注册
*
* @param request
* @param response
* @param page
* @return
*/
public String register(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了 ForeServlet register方法");
Map<String, String> params = new HashMap<>();
InputStream inputStream = super.parseUpload(request, params);
System.out.println(params);
String name = params.get("name");
String password = params.get("password");
System.out.println(name);
// 判断用户名是否存在
boolean exist = userDAO.isExists(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";
}
/**
* 登录
*
* @param request
* @param response
* @param page
* @return
*/
public String login(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了 ForeServlet login方法");
Map<String, String> params = new HashMap<>();
InputStream inputStream = super.parseUpload(request, params);
System.out.println(params);
String name = params.get("name");
String password = params.get("password");
// 登录
User user = userDAO.get(name, password);
if (null == user) {
request.setAttribute("msg", "账号密码错误");
return "login.jsp";
}
// 将账号密码储存在Session中
request.getSession().setAttribute("user", user);
return "@forehome";
}
/**
* 登出
*
* @param request
* @param response
* @param page
* @return
*/
public String logout(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了 ForeServlet logout方法");
request.getSession().removeAttribute("user");
return "@forehome";
}
/**
* 检查用户是否登录
*
* @param request
* @param response
* @param page
* @return
*/
public String checkLogin(HttpServletRequest request, HttpServletResponse response, Page page) {
User user = (User) request.getSession().getAttribute("user");
if (user != null) {
return "%success";
}
return "%fail";
}
/**
* 模态登录框通过 Ajax 方法登录
*
* @param request
* @param response
* @param page
* @return
*/
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 (user == null)
return "%fail";
request.getSession().setAttribute("user", user);
return "%success";
}
/**
* 显示产品页
*
* @param request
* @param response
* @param page
* @return
*/
public String product(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了 ForeServlet product方法");
int pid = Integer.parseInt(request.getParameter("pid"));
Product p = productDAO.get(pid);
// 获取产品的single图片和detail图片
List<ProductImage> productSingleImages = productImageDAO.list(p, ProductImageDAO.type_single);
List<ProductImage> productDetailImages = productImageDAO.list(p, ProductImageDAO.type_detail);
p.setProductSingleImages(productSingleImages);
p.setProductDetailImages(productDetailImages);
//p.setFirstProductImage(productSingleImages.get(0));
// 获取产品属性信息
List<PropertyValue> pvs = propertyValueDAO.list(p.getId());
// 获取产品评价信息
List<Review> reviews = reviewDAO.list(p.getId());
// 设置产品销量数和评价数
productDAO.setSaleAndReviewNumber(p);
request.setAttribute("p", p);
request.setAttribute("pvs", pvs);
request.setAttribute("reviews", reviews);
return "product.jsp";
}
/**
* 分类页面
*
* @return
*/
public String category(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了ForeServlet category方法");
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 中
request.setAttribute("c", c);
return "category.jsp";
}
/**
* 搜索功能
*
* @param request
* @param response
* @param page
* @return
*/
public String search(HttpServletRequest request, HttpServletResponse response, Page page) {
System.out.println("调用了ForeServlet search方法");
String keyword = request.getParameter("keyword");
List<Product> ps = null;
// 加入异常,防止崩溃
try {
ps = productDAO.search(keyword, 0, 50);
} catch (Exception e) {
e.printStackTrace();
}
// 设置产品的销量和评论
productDAO.setSaleAndReviewNumber(ps);
request.setAttribute("ps", ps);
return "sear
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
一、项目简述 功能: 前台: * 用户模块 * 分类模块 * 商品模块 * 购物车模块 * 订单模块 后台: * 管理员模块 * 分类管理模块 * 商品管理模块 * 订单模块 二、项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: JSP + C3P0+ Servlert + html+ css + JavaScript + JQuery + Ajax + Fileupload等等。
资源推荐
资源详情
资源评论
收起资源包目录
Java项目:仿天猫网上商城项目(java+jsp+servlet+mysql+ajax) (291个子文件)
ForeServlet.class 13KB
ProductDAO.class 12KB
OrderItemDAO.class 10KB
OrderDAO.class 9KB
PropertyValueDAO.class 8KB
ReviewDAO.class 8KB
UserDAO.class 7KB
ProductImageServlet.class 6KB
BaseBackServlet.class 6KB
ProductImageDAO.class 6KB
PropertyDAO.class 6KB
BaseForeServlet.class 6KB
ProductServlet.class 5KB
CategoryServlet.class 5KB
CategoryDAO.class 5KB
Order.class 4KB
PropertyServlet.class 4KB
Product.class 4KB
UserServlet.class 3KB
ImageUtil.class 3KB
ForeAuthFilter.class 3KB
BackServletFilter.class 3KB
OrderServlet.class 2KB
ForeServletFilter.class 2KB
Category.class 2KB
Page.class 2KB
User.class 1KB
Review.class 1KB
EncodingFilter.class 1KB
OrderItem.class 1KB
PropertyValue.class 1KB
C3P0Util.class 1KB
ProductImage.class 961B
Property.class 955B
ProductDateComparator.class 816B
ProductAllComparator.class 768B
ProductSaleCountComparator.class 749B
ProductReviewComparator.class 742B
ProductPriceComparator.class 741B
DateUtil.class 698B
DBUtil.class 424B
.classpath 1KB
org.eclipse.wst.common.component 656B
org.eclipse.wst.jsdt.ui.superType.container 49B
bootstrap.css 143KB
bootstrap.min.css 118KB
style.css 37KB
bootstrap-theme.css 26KB
bootstrap-theme.min.css 23KB
style.css 1KB
glyphicons-halflings-regular.eot 20KB
logo2.gif 1.57MB
logo1.gif 252KB
logo.gif 77KB
wangwang.gif 4KB
icon.ico 192B
ForeServlet.java 17KB
ProductDAO.java 11KB
OrderDAO.java 10KB
OrderItemDAO.java 9KB
PropertyValueDAO.java 7KB
ReviewDAO.java 6KB
UserDAO.java 6KB
ProductImageServlet.java 6KB
ProductServlet.java 5KB
BaseBackServlet.java 5KB
PropertyDAO.java 5KB
CategoryServlet.java 4KB
ProductImageDAO.java 4KB
CategoryDAO.java 4KB
BaseForeServlet.java 4KB
Order.java 4KB
PropertyServlet.java 3KB
Product.java 3KB
ForeServletFilter.java 2KB
UserServlet.java 2KB
ImageUtil.java 2KB
Page.java 2KB
OrderServlet.java 2KB
ForeAuthFilter.java 2KB
BackServletFilter.java 1KB
DBUtil.java 1KB
User.java 979B
Category.java 944B
Review.java 943B
OrderItem.java 872B
EncodingFilter.java 825B
C3P0Util.java 755B
PropertyValue.java 750B
Property.java 550B
ProductImage.java 544B
DateUtil.java 386B
ProductAllComparator.java 323B
ProductPriceComparator.java 295B
ProductDateComparator.java 291B
ProductReviewComparator.java 286B
ProductSaleCountComparator.java 285B
643.jpg 411KB
650.jpg 408KB
639.jpg 340KB
共 291 条
- 1
- 2
- 3
qq1334611189
- 粉丝: 7242
- 资源: 421
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页