package cn.easybuy.web.backend;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.easybuy.entity.Product_category;
import cn.easybuy.service.product.Product_CategoryService;
import cn.easybuy.service.product.Product_CategoryServiceImpl;
import cn.easybuy.utils.CategoryPage;
public class CategoryListServlet extends HttpServlet {
public CategoryListServlet() {
super();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action = request.getParameter("action");
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
if(action.equals("pageShow")){
Product_CategoryService pcs = new Product_CategoryServiceImpl();
CategoryPage page = new CategoryPage();
String pageNo = request.getParameter("pageNo");
//如果页号为空 则给个初始值为1 代表首次初始化页面
if(pageNo==null){
pageNo="1";
}
//设置当前页面号
page.setPageNo(Integer.parseInt(pageNo));
//设置每页条数
String pageSize = "5";
page.setPageSize(Integer.parseInt(pageSize));
//获取总数
int DataCount = pcs.getCount();
//设置总数
page.setDataNum(DataCount);
//设置当前集合对象
page.setList(pcs.getCategoryList(Integer.parseInt(pageNo), Integer.parseInt(pageSize)));
//将分页对象page设置到作用域中
request.setAttribute("page", page);
//将全部分类设置到作用域中,使用page.list.parseID == CatagoryList.get(0).ID 来展示父ID
request.setAttribute("CatagoryList", pcs.getList());
//转发到分类列表页面按照分页展示
request.getRequestDispatcher("Member_CategoryList.jsp").forward(request, response);
}else if(action.equals("del")){
String id = request.getParameter("id");
Product_CategoryService pcs = new Product_CategoryServiceImpl();
int i = pcs.delCategorys(id);
System.out.println(i);
if(i==-1){
out.print("<script>");
out.print("alert('该分类下存在子分类,无法删除');");
out.print("window.location.href='CategoryListServlet?action=pageShow';");
out.print("</script>");
}else if(i==-2){
out.print("<script>");
out.print("alert('该分类下存在商品,无法删除!');");
out.print("window.location.href='CategoryListServlet?action=pageShow';");
out.print("</script>");
}else if(i>0){
out.print("<script>");
out.print("alert('删除成功!');");
out.print("window.location.href='CategoryListServlet?action=pageShow';");
out.print("</script>");
}else{
out.print("<script>");
out.print("alert('删除失败!');");
out.print("window.location.href='CategoryListServlet?action=pageShow';");
out.print("</script>");
}
}else if(action.equals("forward")){ //新增分类 控制页面转发 类型集合赋值作用域中 新增分类可以取出分类进行选择
Product_CategoryService pcs = new Product_CategoryServiceImpl();
List<List<Product_category>> pcList=pcs.getList();
String ToPage = request.getParameter("ToPage");
if(ToPage.equals("ToAdd1")){
request.getRequestDispatcher("Member_UpdateCategory1.jsp").forward(request, response);
}else if(ToPage.equals("ToAdd2")){
request.setAttribute("pcList", pcList);
request.getRequestDispatcher("Member_UpdateCategory2.jsp").forward(request, response);
}else if(ToPage.equals("ToAdd3")){
request.setAttribute("pcList", pcList);
request.getRequestDispatcher("Member_UpdateCategory3.jsp").forward(request, response);
}
}else if(action.equals("update")){
Product_CategoryService pcs = new Product_CategoryServiceImpl();
String id = request.getParameter("id");
Product_category pc = pcs.getProductCategoryById(id);
List<List<Product_category>> pcList=pcs.getList();
request.setAttribute("productCategory", pc);
if(pc.getType()==1){
//执行修改一级分类
request.getRequestDispatcher("Member_UpdateCategory1.jsp").forward(request, response);
}else if(pc.getType()==2){
//执行修改二级分类
//将集合存request作用域中
request.setAttribute("pcList", pcList);
request.getRequestDispatcher("Member_UpdateCategory2.jsp").forward(request, response);
}else if(pc.getType()==3){
//执行修改三级分类
//将集合存request作用域中
request.setAttribute("pcList", pcList);
request.getRequestDispatcher("Member_UpdateCategory3.jsp").forward(request, response);
}
}else if(action.equals("add1")){
String id = request.getParameter("id");
//id等于0代表新增,数据库中自增列从1开始
if(Integer.parseInt(id.trim())==0){
//获取值(一级分类只需要名称 父分类为0 类型为1)
String name = request.getParameter("name");
//封装对象
Product_category pc=new Product_category();
pc.setName(name);
pc.setParentId(0);
pc.setType(1);
//创建业务逻辑层对象 调用新增方法
Product_CategoryService pcs = new Product_CategoryServiceImpl();
int i = pcs.addCategory(pc);
if(i>0){
out.print("<script>");
out.print("alert('新增成功!');");
out.print("window.location.href='CategoryListServlet?action=pageShow';");
out.print("</script>");
}else{
out.print("<script>");
out.print("alert('新增成功!');");
out.print("window.location.href='CategoryListServlet?action=pageShow';");
out.print("</script>");
}
}else{
//ID不等于0代表修改
//获取值
String name = request.getParameter("name");
//分装分类对象
Product_category pc = new Product_category();
pc.setId(Integer.parseInt(id.trim()));
pc.setName(name);
pc.setParentId(0);
pc.setType(1);
Product_CategoryService pcs = new Product_CategoryServiceImpl();
int i = pcs.updateCategory(pc);
if(i>0){
out.print("<script>");
out.print("alert('修改成功!');");
out.print("window.location.href='CategoryListServlet?action=pageShow';");
out.print("</script>");
}else{
out.print("<script>");
out.print("alert('修改失败!');");
out.print("window.location.href='CategoryListServlet?action=pageShow';");
out.print("</script>");
}
}
}else if(action.equals("add2")){
String id = request.getParameter("id");
//id等于0代表新增,数据库中自增列从1开始
if(Integer.parseInt(id.trim())==0){
//获取值(二级分类需要名称,父分类ID 类型为2)
String name = request.getParameter("name");
//封装对象
Product_category pc=new Product_category();
pc.setName(name);
pc.setParentId(Integer.parseInt(request.getParameter("categoryLevel1Id")));
pc.setType(2);
//创建业务逻辑层对象 调用新增方法
Product_CategoryService pcs = new Product_CategoryServiceImpl();
int i = pcs.addCategory(pc);
if(i>0){
out.print("<script>");
out.print("alert('新增成功!');");
out.print("window.location.href='CategoryListServlet?action=pageShow';");
out.print("</script>");
}else{
out.print("<script>");
out.print("alert('新增成功!');");
out.print("window.location.href='CategoryListServlet?action=pageShow';");
out.print("</script>");
}
}else{
//ID不等于0代表修改
//获取值
String name = request.getParameter("name");
//分装分类
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
easybuy易买网,北大青鸟s2结业项目 (294个子文件)
ProductListServlet.class 9KB
CartServlet.class 8KB
ProductDaoImpl.class 7KB
UserDaoImpl.class 7KB
CategoryListServlet.class 7KB
Product_categoryDaoImpl.class 5KB
OrderDaoImpl.class 5KB
UserListServlet.class 5KB
OrderServlet.class 4KB
UserRegister.class 3KB
Order_detailDaoImpl.class 3KB
UserLogin.class 3KB
NewsDaoImpl.class 3KB
Order_DetailServiceImpl.class 3KB
ShoppingCart.class 3KB
IndexServlet.class 3KB
BaseDao.class 3KB
User_AddressDaoImpl.class 3KB
Product_CategoryServiceImpl.class 2KB
UserServiceImpl.class 2KB
Product.class 2KB
ProductServiceImpl.class 2KB
OrderServiceImpl.class 2KB
User.class 2KB
NewsListServlet.class 2KB
CartServiceImpl.class 2KB
Order.class 2KB
DataSourceUtil.class 2KB
MemcachedUtils.class 2KB
ProductServlet.class 2KB
SelProductServlet.class 2KB
EncodeFilter.class 2KB
CategoryPage.class 2KB
ProductPage.class 2KB
OrderPage.class 2KB
NewsPage.class 2KB
UserPage.class 2KB
User_Address.class 1KB
ConfigManager.class 1KB
ShoppingCartItem.class 1KB
Order_detail.class 1KB
OrderAndProduct.class 1KB
Product_category.class 1KB
News.class 1KB
UserAddressServiceImpl.class 1012B
NewsServiceImpl.class 992B
ProductService.class 862B
ProductDao.class 842B
UserService.class 784B
UserDao.class 776B
Product_categoryDao.class 688B
Product_CategoryService.class 661B
SecurityUtils.class 581B
OrderDao.class 540B
OrderService.class 537B
Order_DetailService.class 426B
CartService.class 380B
UserAddressService.class 376B
NewsService.class 364B
User_AddressDao.class 361B
Order_detailDao.class 355B
NewsDao.class 347B
.classpath 607B
org.eclipse.wst.common.component 559B
org.eclipse.wst.jsdt.ui.superType.container 49B
style.css 99KB
ShopShow.css 2KB
MagicZoom.css 1KB
mysql-connector-java-5.1.25-bin.jar 829KB
sqljdbc2008.jar 570KB
log4j-1.2.17.jar 478KB
fastjson-1.2.6.jar 411KB
standard.jar 384KB
commons-codec-1.9.jar 258KB
javax.persistence.jar 127KB
commons-pool-1.5.6.jar 98KB
commons-io-1.3.2.jar 86KB
java_memcached-release_2.6.3.jar 79KB
javax.servlet.jsp.jar 77KB
javax.servlet.jar 68KB
commons-fileupload-1.2.1.jar 56KB
javax.ejb.jar 46KB
javax.resource.jar 43KB
javax.jms.jar 25KB
slf4j-api-1.6.1.jar 25KB
jstl.jar 20KB
javax.transaction.jar 9KB
javax.annotation.jar 8KB
slf4j-simple-1.6.1.jar 7KB
CategoryListServlet.java 10KB
ProductListServlet.java 9KB
CartServlet.java 8KB
UserDaoImpl.java 7KB
ProductDaoImpl.java 6KB
UserListServlet.java 5KB
OrderDaoImpl.java 4KB
Product_categoryDaoImpl.java 4KB
OrderServlet.java 3KB
UserLogin.java 3KB
UserRegister.java 3KB
共 294 条
- 1
- 2
- 3
那晚安咯
- 粉丝: 3
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 【全年行事历】行政部全年活动计划表- A公司.xls
- 【全年行事历】活动复盘表.xlsx
- 【全年行事历】活动推广进度表.xlsx
- 【全年行事历】旅游团建行程安排表-XX山.xlsx
- 【全年行事历】旅行团建活动方案.pptx
- 【全年行事历】某公司团建活动方案-【户外烧烤】.doc.baiduyun.uploading.cfg
- 【全年行事历】企业文化年度活动计划表.xlsx
- 【全年行事历】年度员工关怀计划表.xlsx
- 【全年行事历】年度行政活动计划表.xlsx
- 【全年行事历】企业团队建设活动策划.pptx
- 【全年行事历】全年活动计划.xls
- 【全年行事历】团队建设企业文化行事历——工作计划.xlsx
- 【全年行事历】企业员工夏季团建活动策划一天.pptx
- 【全年行事历】团建费用分析.xlsx
- 【全年行事历】团建行程安排及出行清单.xlsx
- 【全年行事历】团建活动采购预算清单.xlsx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论5