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

📄 productaction.java

📁 网上购物系统用SSH实现的
💻 JAVA
字号:
package cn.com.tarena.ecport.web.action;

import java.util.List;

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 org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.com.tarena.ecport.biz.IProductBusiness;
import cn.com.tarena.ecport.pojo.Product;

public class ProductAction extends MappingDispatchAction {
	private IProductBusiness productbiz;
	
	public void setProductbiz(IProductBusiness productbiz) {
		this.productbiz = productbiz;
	}
	//	查出Product表中的所有项,放入list 传入Index.jsp显示
	public ActionForward toIndex(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
//		IProductBusiness productbiz = (IProductBusiness)BusinessFactory.getBusiness(IProductBusiness.class.getName());
//		ApplicationContext context = new ClassPathXmlApplicationContext("beans_hibernate.xml");
//		IProductBusiness productbiz = (IProductBusiness)context.getBean("productBusinessproxy");
		List list = productbiz.findAllProducts();
		request.setAttribute("productList", list);
		return mapping.findForward("toIndex");
	}
//	从查询字符串中传来的id通过ProductDAO查询数据库得到相应的Product对象
//	放入request中给ProductDetail的JSP用。
	public ActionForward toProductDetail(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
//		ApplicationContext context = new ClassPathXmlApplicationContext("beans_hibernate.xml");
//		IProductBusiness productbiz = (IProductBusiness)context.getBean("productBusinessproxy");
		Product product = productbiz.getProductById(Long.parseLong(request.getParameter("id")));
		request.setAttribute("product", product);
		return mapping.findForward("toProductDetail");
	}
	
}

⌨️ 快捷键说明

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