📄 userissueshopservlet.java
字号:
package com.jc.taobao.gjj.action;
import java.io.IOException;
import java.io.PrintWriter;
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.TypeInfoBean;
import com.jc.taobao.gjj.logic.UserInfoBean;
import com.jc.taobao.gjj.logic.UserSellShop;
public class UserissueShopServlet extends HttpServlet {
String fabushopinformation=null;
/**
* Constructor of the object.
*/
public UserissueShopServlet() {
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");
PrintWriter out = response.getWriter();
/*用于判断是否插入成功*/
int issorfail=0;
/*从页面获取所需要的值*/
String shopname=request.getParameter("shopname");
String typename=request.getParameter("shoptype");
String shopprice=request.getParameter("shopprice");
String shopmake=request.getParameter("shopmake");
String shopstate=request.getParameter("shopstate");
String shopautor=request.getParameter("shopuser");
String shoppic=request.getParameter("shopphoto");
String shopdesc=request.getParameter("shopdesc");
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();
issorfail=usersellshop.UserSellShopissucessorfail(shop,user, number, shoppic, servicepath);
if(issorfail>0)
{
response.sendRedirect("/taobao/Buyshop.jsp?buyshopid="+issorfail);
}
else
{
out.print("<script>alert('对不起,商品添加失败!');window.history.go(-1);</script>");
}
}
/**
* 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 + -