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

📄 addshopservlet.java

📁 一个仿造淘宝的jsp网站。功能比较完善
💻 JAVA
字号:
package com.jc.taobao.gjj.action;

import java.io.IOException;
import java.util.ArrayList;

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

import com.jc.taobao.gjj.entity.ShopInfo;
import com.jc.taobao.gjj.entity.ShopNuminfo;
import com.jc.taobao.gjj.entity.TypeInfo;
import com.jc.taobao.gjj.entity.UserInfo;
import com.jc.taobao.gjj.logic.ShopInfoBean;
import com.jc.taobao.gjj.logic.ShopNuminfoBean;
import com.jc.taobao.gjj.logic.TypeInfoBean;
import com.jc.taobao.gjj.logic.UserInfoBean;
import com.jc.taobao.gjj.logic.UserSellShop;

public class AddShopServlet extends HttpServlet {
	String managershopinformation=null;

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

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

	/**
	 * 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 {

		response.setContentType("text/html");
		/*用于判断是否插入成功*/
		int issorfail=0;
		
		/*从页面获取所需要的值*/
		String shopname=request.getParameter("addshopname");
		String typename=request.getParameter("addshoptype");
		String shopprice=request.getParameter("addshopprice");
		String shopmake=request.getParameter("addshopmake");
		String shopstate=request.getParameter("addshopstateradio");
		String shopautor=request.getParameter("addshopuser");
		String shoppic=request.getParameter("aashoppic");
		String shopdesc=request.getParameter("addshopdesc");
		String shopnumber=request.getParameter("shopnumber");
		String servicepath=request.getRealPath("image/usersell");

		
		/*查询出对应的类别编号*/
		TypeInfoBean tbean=new TypeInfoBean();
		ArrayList al1=tbean.getTypeinfoquerybyTypename(typename);
		TypeInfo type=(TypeInfo)al1.get(0);
		int typeid=type.getTid();
		
		/*确定对应的状态编号*/
		int stateid=2;
		if(shopstate=="上架")
		{
			stateid=1;
		}else
	    {
			stateid=2;
		}
		
		 /*查询出对应的用户编号*/
		UserInfoBean ubean=new UserInfoBean();
		UserInfo user=new UserInfo();
		user.setUsername(shopautor);
		ArrayList al2=(ArrayList)ubean.getquerybyuserusename(user);
		UserInfo user2=(UserInfo)al2.get(0);
		int userid=user2.getUserid();
		
		/*设置价格*/
		float price=Float.parseFloat(shopprice);
		
		/*设置存入服务器的图片地址*/
		String x=shoppic.substring(shoppic.lastIndexOf("\\")+1, shoppic.length());
		String photopic="image/usersell/"+x;
		
		/*给实体添加属性*/
		ShopInfo shop=new ShopInfo();
		shop.setTid(typeid);
		shop.setStateid(stateid);
		shop.setUserid(userid);
		shop.setShopname(shopname);
		shop.setPrice(price);
		shop.setShopmake(shopmake);
		shop.setShopphoto(photopic);
		shop.setShopdesc(shopdesc);
		 
		 /*为库存表添加实体属性*/
		 int number=Integer.valueOf(shopnumber);
		
		 UserSellShop usersellshop=new UserSellShop();
		 if(usersellshop.UserSellShopissucessorfail(shop,user, number, shoppic, servicepath)>0)
		 {
			 issorfail=1;
		 }
		 if(issorfail==1)
		 {
			 managershopinformation="恭喜你,商品添加成功!";
		 }
		 else
		 {
			 managershopinformation="对不起,商品添加失败!";
		 }
		 request.setAttribute("fabushopinformation", managershopinformation);
		 request.getRequestDispatcher("/ShopManager.jsp").forward(request, response);
	
	}

	/**
	 * 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 + -