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

📄 goodsinfosave.java

📁 基于J2EE的网络物流系统 用户操作: 1. 录入出库商品信息 2. 查询出库单信息 3. 录入入库商品信息 4. 查询入库单信息 5. 查询商品位置信息 6. 查询商品信息 7. 查
💻 JAVA
字号:
package com.logistic.servlet;

import java.io.IOException;
import java.lang.NumberFormatException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.logistic.data.DataConnect;
import com.logistic.business.GoodsManager;
import java.sql.Statement;
import java.sql.ResultSet;

public class GoodsInfoSave extends HttpServlet {

	private static final long serialVersionUID = -2305260907601477327L;
	HttpSession session=null;
	DataConnect dc=new DataConnect();
	Statement   stat=null;
	ResultSet   rs=null;
	int       goodsid;
	String     id=null;
	String   name=null;
	String  cateid=null;
	String  supplyid=null;
	String    abc=null;
	String  province=null;
	String  city=null;
	String  stockid=null;
	float  price=0;
	int    stocknum=0;
	int    flag=0;
	String   orderdate=null;
	String   stockindate=null;
	String unit=null;
	String regionid=null;
	String typeid=null;
	RequestDispatcher requestdispatcher;
	
	public GoodsInfoSave() {
		super();
	}



	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("GB2312");
		response.setContentType("text/html; charset=gb2312");
		session=request.getSession();
/*--------取得goodsinfotable表的GoodsId并转换成整型,并生成下条记录的GoodsId-------*/		
		String sql="select * from goodsinfotable order by ID desc limit 1";
		try{
			stat=dc.getStmtread();
			rs  =stat.executeQuery(sql);
			rs.previous();
			while(rs.next()){
				goodsid=Integer.valueOf(rs.getInt("GoodsId"));
			}
			if(goodsid>0){
				goodsid+=1;
			     }else{
				    goodsid=10000+1;
			         }
			
		}catch(Exception ex){ex.printStackTrace();}finally{dc.close();}
/*------------从goodsinfosave.jsp页面读取商品信息保存到数据库---------------*/
		try{
			
			price=Float.valueOf((String)request.getParameter("goodsprice"));
			stocknum=Integer.valueOf((String)request.getParameter("stockinnumber"));
			
		}catch(NumberFormatException ex){
			System.out.print("Price或StockNum类型转换错误!");
			ex.printStackTrace();
		}
		
		id=String.valueOf(goodsid);
		name=(String)request.getParameter("goodsname");
		cateid=(String)request.getParameter("goodscate");
		supplyid=(String)request.getParameter("goodssupply");
		abc=(String)request.getParameter("goodsabc");
		province=(String)request.getParameter("goodsprovince");
		city=(String)request.getParameter("goodscity");
		stockid=(String)request.getParameter("goodsstockadd");

		orderdate=(String)request.getParameter("orderdate");
		stockindate=(String)request.getParameter("stockindate");
		unit=(String)request.getParameter("goodsunit");
		regionid=(String)request.getParameter("stockregion");
		typeid=(String)request.getParameter("goodstype");
		
				
		try{
			 flag=-10;
			 GoodsManager gm=new GoodsManager();
			 flag=gm.AddGoods(id, name, cateid, supplyid, abc, province,city, stockid, price, stocknum, orderdate, stockindate, unit, regionid,typeid);
			 if(flag>0){
			
				 session.setAttribute("success", "商品信息保存成功!");
				 requestdispatcher=request.getRequestDispatcher("/viewpage/datainput/goodsinfosave.jsp");
				 requestdispatcher.forward(request, response);
			 }else{
			
				 	session.setAttribute("errors", "商品信息保存失败!");
				 	requestdispatcher=request.getRequestDispatcher("/errors/errorpage.jsp");
				 	requestdispatcher.forward(request, response);
			 }
		
		}catch(Exception ex){flag=-1;ex.printStackTrace();}finally{dc.close();}
		
	}
		
	public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
	        doPost(request,response);
        }


}

⌨️ 快捷键说明

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