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

📄 foodcartaction.java

📁 SSH 开发网上订餐系统。由于SSH相关包太大不方便上传。请自行导入。
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.struts.action;

/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */

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 com.web.model.FoodInfo;
import com.web.servic.FoodInfo_Intef;
import com.web.util.ShoppingCart;


public class FoodCartAction extends Action {
	private FoodInfo_Intef foodInfo_Intef ;//servic 接口函数
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		System.out.print("gogogo1");
		ShoppingCart cart=(ShoppingCart) request.getSession().getAttribute("FoodInfoCartList");
		System.out.print("gogogo2");
		if(cart==null){
			cart=new ShoppingCart();
		}
		FoodInfo food=null;
		String add=request.getParameter("Add");
		if(add!=null){
			food=foodInfo_Intef.findById(add);
			cart.addFood(food.getFId(),food);
			request.getSession().setAttribute("FoodInfoCartList", cart);
			return mapping.findForward("pageControl");
		}
		
		String edit=request.getParameter("Edit");
		System.out.print("^^^^^^^^^^^"+edit);
		if(edit!=null){
			try {
				System.out.print("^^^^^^^^^^^");
				String quantity=request.getParameter("foodQuantity");
				System.out.println("^^^^^^^^^^^^^^^"+quantity);
				int foodQuantity=Integer.parseInt(quantity);
				System.out.println("count="+foodQuantity);
				cart.updateFoodQuantity(edit,foodQuantity);
			} catch (NumberFormatException e) {
			}
		}
		
		String buy  = request.getParameter("Buy") ;
		if(buy!=null)
		{
			request.getSession().setAttribute("FoodInfoCartList", cart);
			return mapping.findForward("shopping");
		}
		
		String delete=request.getParameter("Delete");
		if(delete!=null){			
			cart.removeFood(delete);
		}
		String clear=request.getParameter("Clear");
		if(clear!=null){
			cart.clearFoodCart();
			//request.getSession().setAttribute("FoodInfoCartList", cart);
			request.getSession().removeAttribute("FoodInfoCartList") ;
			return mapping.findForward("shopcart");
		}	
		
		request.getSession().setAttribute("FoodInfoCartList", cart);
		return mapping.findForward("shopcart");
	}

	
	public FoodInfo_Intef getFoodInfo_Intef() {
		return foodInfo_Intef;
	}

	public void setFoodInfo_Intef(FoodInfo_Intef foodInfo_Intef) {
		this.foodInfo_Intef = foodInfo_Intef;
	}
}

⌨️ 快捷键说明

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