⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewcategoryaction.java

📁 这是一个网上购物店的源码
💻 JAVA
字号:
package org.digitstore.web.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.digitstore.domain.Category;

import org.springframework.beans.support.PagedListHolder;
import org.digitstore.service.*;

public class ViewCategoryAction extends BaseAction {

    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        String categoryId = request.getParameter("categoryId");
        ProductManager manager = ManagerFactory.createProductManager();
        if (categoryId != null) {
            Category category = manager.getCategory(categoryId);
            PagedListHolder productList = new PagedListHolder(manager
                    .getProductListByCategory(categoryId));
            productList.setPageSize(4);
            request.getSession().setAttribute("ViewProductAction_category",
                    category);
            request.getSession().setAttribute("ViewProductAction_productList",
                    productList);
            request.setAttribute("category", category);
            request.setAttribute("productList", productList);
        } else {
            Category category = (Category) request.getSession().getAttribute(
                    "ViewProductAction_category");
            PagedListHolder productList = (PagedListHolder) request
                    .getSession().getAttribute("ViewProductAction_productList");
            if (category == null || productList == null) {
                throw new IllegalStateException(
                        "Cannot find pre-loaded category and product list");
            }
            String page = request.getParameter("page");
            if ("next".equals(page)) {
                productList.nextPage();
            } else if ("previous".equals(page)) {
                productList.previousPage();
            }
            request.setAttribute("category", category);
            request.setAttribute("productList", productList);
        }
        return mapping.findForward("success");
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -