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

📄 productinsert.java

📁 该源代码实现了系统的进货
💻 JAVA
字号:
package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import operation.ProductOperation;
import com.jspsmart.upload.*;

public class ProductInsert extends HttpServlet
{

	/**
	 * Constructor of the object.
	 */
	public ProductInsert()
	{
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy()
	{
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		doPost(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		request.setCharacterEncoding("gb2312");
		response.setContentType("text/html;charset=gb2312");
		PrintWriter out = response.getWriter();
		
		SmartUpload mySmartUpload=new SmartUpload();
		
		ProductOperation operation = new ProductOperation();
		int productID = operation.addProductId();
	//	String picturename=String.valueOf("productID");
		int count=0;        
		mySmartUpload.initialize(this.getServletConfig(), request,response);	
		try
		{
		mySmartUpload.upload();
		for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
			com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
			if (!myFile.isMissing())
			{
				String path="d:\\upload\\";
				String name=productID+".jpg";
				java.io.File file=new java.io.File(path);
				if(!file.exists())
				{
					boolean result=file.mkdirs();
				    myFile.saveAs(path+name);
				}
				else
				{
					myFile.saveAs(path+name);
				}
				count ++;
			}

		}
		}
		catch(Exception e)
		{
			e.printStackTrace();
			
		}
		
		
		boolean flag = true;
		try
		{
			//获取页面信息
			String providerName = mySmartUpload.getRequest().getParameter("providerName");		
			if (providerName == "")
			{
				out.print("<script>alert('供货商名字不能为空!');window.location.href='ProductInsert.jsp';</script>"); 
				flag = false;
			}
			String productName =mySmartUpload.getRequest().getParameter("productName");	
			if (productName == "")
			{
				out.print("<script>alert('商品名字不能为空!');window.location.href='ProductInsert.jsp';</script>"); 
				flag = false;
			}
			String productSign = mySmartUpload.getRequest().getParameter("productSign");			
			String productType = mySmartUpload.getRequest().getParameter("productType");			
			String productRegulate = mySmartUpload.getRequest().getParameter("productRegulate");			
			String productTax = mySmartUpload.getRequest().getParameter("productTax");			
			String productPlace = mySmartUpload.getRequest().getParameter("productPlace");			
			String productNotice = mySmartUpload.getRequest().getParameter("productNotice");
			
			
			int providerID = operation.addProviderId(providerName);
			
			operation.addProductInfo(flag,productID,providerID,productName,productSign,productType,productRegulate,productTax,productPlace,productNotice);//向操作类传递参数,商品信息录入
			operation.close();
			
			out.print("<script>alert('录入成功!');window.location.href='ProductInsert.jsp';</script>"); 
		}  
		catch(Exception e) 
		{
			System.out.println("productinsertservelet");
			e.printStackTrace();
		}

	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException
	{
		// Put your code here
	}

}

⌨️ 快捷键说明

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