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

📄 wareaddaction.java

📁 一个java写的网上购物系统
💻 JAVA
字号:
package com.hb.myshop.struts.action;

import java.io.File;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

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.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.hb.myshop.idao.ISortDAO;
import com.hb.myshop.idao.IWareDAO;
import com.hb.myshop.po.Sort;
import com.hb.myshop.po.Ware;
import com.hb.myshop.struts.form.WareAddForm;
import com.hb.myshop.tools.PageController;


public class WareAddAction extends Action {
	  private IWareDAO iwareDao;
	  private ISortDAO isortDao;
	
	

	public IWareDAO getIwareDao() {
		return iwareDao;
	}



	public void setIwareDao(IWareDAO iwareDao) {
		this.iwareDao = iwareDao;
	}



	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		HttpSession session=request.getSession();
		WareAddForm form1 = (WareAddForm)form;
		Ware ware=new Ware();
		ISortDAO isortdao=this.getIsortDao();
		String wareid=form1.getWareid();
		String warename=form1.getWarename();
		if(this.getIwareDao().getWare(wareid)!=null){
			String warePic=this.getIwareDao().getWare(wareid).getWarepic();
			if(warePic!=null&&form1.getWarepic().equals("")){
				ware.setWarepic(warePic);
			}
			else{
				System.out.println(form1.getWarepic());
				File file=new File(form1.getWarepic());
				System.out.println(form1.getWarepic());
				 String ccc="D:/workspace/MyShop/WebRoot/images/"+file.getName();
                   try {
                  	 java.io.FileInputStream in =new java.io.FileInputStream(file);
 				        java.io.FileOutputStream out =new java.io.FileOutputStream(new File(ccc));
 				         byte Buff[]=new byte[1024];
 				         int len;
 				         while((len=in.read(Buff))>-1){
 				           out.write(Buff,0,len);
 				         }
 				         in.close();
 				         out.close();
					} catch (Exception e) {e.printStackTrace();}
					System.out.println(file.getName());
		  ware.setWarepic("/MyShop/images/"+file.getName());
		 }
		}
		else{
			 ware.setWarepic(form1.getWarepic());
		}
			
		Sort sort=isortdao.getsort(form1.getSort());
		ware.setWareid(form1.getWareid());
		ware.setWarename(form1.getWarename());
		ware.setWareprice(form1.getWareprice());
		ware.setWareinfo(form1.getWareinfo());
		ware.setSort(sort);
		if(wareid.equals("")||warename.equals(""))
		{   
			//return new ActionForward("/JSP/WareAddError.jsp");
			ActionMessages errors=new ActionMessages();
			ActionMessage error=new ActionMessage("wareaddfail");
			errors.add("addfail",error);
			this.saveErrors(request, errors);
			return new ActionForward("/JSP/WareAddError.jsp");
		}
		else
		{
			IWareDAO iwaredao=this.getIwareDao();
			iwaredao.addAndupWare(ware);
			List list=iwaredao.getAllWares();
			String pageIndex = request.getParameter("pageIndex");
			if(pageIndex == null)
			{
				pageIndex = "1";
			}
			PageController pc = (PageController) request.getAttribute("pc");
			if (pc == null)
			{
				pc = new PageController();
				pc.setBigList(list);
				request.setAttribute("pc", pc);
			}
			pc.setCurrentPageIndex(Integer.parseInt(pageIndex));
			return new ActionForward("/JSP/ware.jsp");
		}
		
	}



	public ISortDAO getIsortDao() {
		return isortDao;
	}



	public void setIsortDao(ISortDAO isortDao) {
		this.isortDao = isortDao;
	}
}
	
	
	
	

⌨️ 快捷键说明

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