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

📄 addfoodaction.java

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

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
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.upload.FormFile;

import com.struts.form.AddfoodForm;
import com.web.model.FoodInfo;
import com.web.model.FoodStyle;
import com.web.servic.FoodInfo_Intef;
import com.web.servic.FoodStyle_Intef;

/** 
 * MyEclipse Struts
 * Creation date: 09-08-2008
 * 
 * XDoclet definition:
 * @struts.action path="/addfood" name="addfoodForm" input="/addfood.jsp" scope="request" validate="true"
 */
public class AddfoodAction extends Action {
	/*
	 * Generated Methods
	 */
	private FoodInfo_Intef foodInfo_Intef ;//服务端接口
	private FoodStyle_Intef foodStyle_Intef ;
	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		AddfoodForm aff = (AddfoodForm) form;// TODO Auto-generated method stub
		//System.out.print(")))))))"+aff.getFname());

		if(aff.getFid()==null)
		{
			List foodstylelist = foodStyle_Intef.findAll() ;
			request.getSession().setAttribute("foodstyle_list", foodstylelist) ;
			return mapping.findForward("add") ;
		}
		try{
		FoodInfo foodinfo = new FoodInfo() ;
		FoodStyle foodstyle = new FoodStyle() ;
		foodstyle.setFsId(aff.getFstyle()) ;
		
		foodinfo.setFId(aff.getFid()) ;
		foodinfo.setFName(aff.getFname()) ;
		foodinfo.setFPrice(Float.valueOf(aff.getFprice()).floatValue()) ;
		foodinfo.setFState(Integer.parseInt(aff.getFstate()));
		foodinfo.setFoodStyle(foodstyle) ;
		
		if(!aff.getFtotal().equals("")){		
		foodinfo.setFTotal(Integer.parseInt(aff.getFtotal())) ;
		}
		foodinfo.setFMemo(aff.getFmemo()) ;
		FormFile file=aff.getFlargeimg();
		if(file.getFileName().equals(""))
		{
			foodinfo.setFLargeimage("food/largeimage/default.jpg");
			//System.out.println("null'''''''''''''") ;	
		}
		else
		{
			upload(file,"largeimage") ;
			String largeimage="food/largeimage/"+file.getFileName() ;
			foodinfo.setFLargeimage(largeimage) ;
			//System.out.println("No null'''''''''''''") ;
			//System.out.print("***************"+file.getFileName()) ;
		}
		if(file.getFileName().equals(""))
		{
			foodinfo.setFSmallimage("food/smallimage/default.jpg");
		}
		else
		{
			file=aff.getFsmallimg() ;
			upload(file,"smallimage") ;
			String smallimage = "food/smallimage/"+file.getFileName() ;
			foodinfo.setFSmallimage(smallimage) ;
		}		
		foodInfo_Intef.save(foodinfo) ;
		}
		catch(Exception e)
		{
			request.getSession().setAttribute("addfood", "添加失败 请重新添加!") ;
			return mapping.findForward("fail") ;
		}
		return mapping.findForward("suc");
	}

	public FoodInfo_Intef getFoodInfo_Intef() {
		return foodInfo_Intef;
	}
	public void setFoodInfo_Intef(FoodInfo_Intef foodInfo_Intef) {
		this.foodInfo_Intef = foodInfo_Intef;
	}
	public FoodStyle_Intef getFoodStyle_Intef() {
		return foodStyle_Intef;
	}
	public void setFoodStyle_Intef(FoodStyle_Intef foodStyle_Intef) {
		this.foodStyle_Intef = foodStyle_Intef;
	}
	public void upload(FormFile file,String path) 
	{
		String fileName=file.getFileName();
		String newFileName="food/"+path+"/"+fileName;
	   	 String dir=servlet.getServletContext().getRealPath("/");
	   	 try {
					File f=new File(dir+newFileName);
					System.out.println("path="+dir+"/"+newFileName);
					f.delete();
					InputStream is=file.getInputStream();
					System.out.println("^^^^^^^^^^^^^^"+"input") ;
					System.out.println("^^^^^^^^^^^^^^"+is.toString()) ;
					OutputStream os=new FileOutputStream(dir+"food/smallimage/"+fileName);
					//OutputStream os=new FileOutputStream("F:/");
					//byte []buffer=file.getFileData();
					os.write(file.getFileData());
					os.close();
					is.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
	}
}

⌨️ 快捷键说明

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