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

📄 brandoperation.java

📁 基于struts+hibernate的电子商务网站。可运行。数据库mysql
💻 JAVA
字号:
/**
  * @(#)tarena.action.BrandOperation.java  2008-11-5  
  * Copy Right Information	: Tarena
  * Project					: xindou
  * JDK version used		: jdk1.6.4
  * Comments				: 品牌操作类。
  * Version					: 1.0
  * Sr	Date		Modified By		Why & What is modified
  * 1.	2008-11-5 	小猪     		新建
  **/
package tarena.action;

import java.util.List;
import java.util.Set;
import java.util.Vector;

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.apache.struts.actions.MappingDispatchAction;

import tarena.dao.BrandDAO;
import tarena.dao.pages.BrandListDAO;
import tarena.data.BrandShow;
import tarena.entity.Brand;
import tarena.entity.Product;
import tarena.global.MessageOperate;


 /**
 * 品牌操作类。<br>
 * 列出所有品牌、某品牌等。
 * 2008-11-5
 * @author		达内科技[Tarena Training Group]
 * @version	1.0
 * @since		JDK1.6(建议) 
 * @author		Administrator
 */
@SuppressWarnings("unchecked")
public class BrandOperation extends MappingDispatchAction {

	public ActionForward brandList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		BrandListDAO listDAO = new BrandListDAO();
		List<String> initals = listDAO.listBrandInitalByOrder();
		List<BrandShow> allbrands = new Vector<BrandShow>();
		for(String inital:initals)
			allbrands.add(new BrandShow(inital,listDAO.listBrandByInital(inital)));
		
		request.setAttribute("title", "品牌总目录");
		request.setAttribute("initals", initals);
		request.setAttribute("allbrands", allbrands);
		return mapping.findForward("brandlist");
	}
	
	public ActionForward brand(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		try {
			Integer bid = new Integer(request.getParameter("bid"));		
			Brand brand = new BrandDAO().findById(bid);
			Set<Product> products = brand.getProducts();
			if(products.size()==0) throw new RuntimeException();
			request.setAttribute("products", products);
		} catch (RuntimeException e) {
			dealError(mapping, request);
		}
		
		
		return mapping.findForward("brand");
	}
	private ActionForward dealError(ActionMapping mapping, HttpServletRequest request){
		MessageOperate.setAttribute(request, "非法操作", "操作错误", "您所访问的id为空或不存在!程序将跳转到上一页.", "");
		return mapping.findForward("message");
	}
}

⌨️ 快捷键说明

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