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

📄 itemaction.java

📁 struts hibernate框架 商场买卖
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.shopping.struts.action.item;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.shopping.bo.item.Pager;
import com.shopping.bo.item.PagerHelper;
import com.shopping.dao.UnifyDao;
import com.shopping.factory.DAOFactory;
import com.shopping.vo.Category;

public class ItemAction extends DispatchAction {
	public ActionForward all(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		UnifyDao ud = null;
		try {
			ud = (UnifyDao) DAOFactory
					.getBean("com.shopping.dao.imp.ItemDaoImp");
		} catch (InstantiationException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		List ca = null;
		int totalRows;
		int startRow;

		try {
			totalRows = ud.getRows();
			Pager pager = PagerHelper.getPager(request, totalRows);
			ca = ud.getTable(pager.getPageSize(), pager.getStartRow());
			System.out.println(ca.size());
			request.getSession().setAttribute("itemPage", pager);
			request.getSession().setAttribute("List", ca);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return mapping.findForward("success");
	}

	public ActionForward search(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		int catId = Integer.parseInt(request.getParameter("id"));
		
		String keyword = request.getParameter("Keyword");
		if(keyword==null){
			keyword = (String)request.getSession().getAttribute("keyword");
		}

		UnifyDao ud = null;
		try {
			ud = (UnifyDao) DAOFactory
					.getBean("com.shopping.dao.imp.ItemDaoImp");
		} catch (InstantiationException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		UnifyDao catDao = null;
		try {
			catDao = (UnifyDao) DAOFactory
					.getBean("com.shopping.dao.imp.CatDaoImp");
		} catch (InstantiationException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		List ca = null;
		int totalRows;
		int startRow;
		Pager pager;

		if (catId==0) {
			totalRows = ud.getRows(keyword);
			pager = PagerHelper.getPager(request, totalRows);
			ca = ud.getTable(keyword,pager.getPageSize(), pager.getStartRow());
			System.out.println(ca.size());
			request.getSession().setAttribute("itemPage", pager);
			request.getSession().setAttribute("List", ca);
			request.getSession().setAttribute("keyword", keyword);
			request.getSession().setAttribute("catId", 0);
		} else {
			
			Category cat = (Category) catDao.getTableById(catId);
			if (cat.getPid() == 0) {
				totalRows = ud.getRows2(keyword,catId);
				pager = PagerHelper.getPager(request, totalRows);
				ca = ud.getTable2(keyword,catId, pager.getPageSize(), pager
						.getStartRow());
				request.getSession().setAttribute("itemPage", pager);
				request.getSession().setAttribute("List", ca);
				request.getSession().setAttribute("keyword", keyword);
				request.getSession().setAttribute("catId", catId);
			} else {
				totalRows = ud.getRows(keyword,catId);
				pager = PagerHelper.getPager(request, totalRows);
				ca = ud.getTable(keyword,catId, pager.getPageSize(), pager
						.getStartRow());
				request.getSession().setAttribute("itemPage", pager);
				request.getSession().setAttribute("List", ca);
				request.getSession().setAttribute("keyword", keyword);
				request.getSession().setAttribute("catId", catId);
			}
		}

		return mapping.findForward("success2");
	}
}

⌨️ 快捷键说明

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