package com.sxt.servlet;
import java.io.File;
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 com.sxt.dao.GoodsDao;
import com.sxt.dao.impl.GoodsDaoImpl;
public class DelGoodsServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String gid = request.getParameter("gid");
String gurl = request.getParameter("gurl");
GoodsDao dao = new GoodsDaoImpl();
PrintWriter out = response.getWriter();
try {
boolean b = dao.delGoods(gid);
if (b) {
// 删除本地图片
File f = new File(request.getServletContext().getRealPath("/")+gurl);
if(f.isFile()){
f.delete();
}
out.print(1);
} else {
out.print(0);
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}