标签:date split eth text bst ase jsp else tps
一、删除商品(数据库) 二、删除商品对应的照片(文件) //这里加?p=p是因为&ids 这里需要这样的格式 String deleteUrl=basePath+"pages/back/admin/goods/GoodsBackServlet/delete?p=p"; public String delete(HttpServletRequest request){ //删除id(数据库)和photo(文件) String msg=null; String url=null; String referer=request.getHeader("referer"); String ids = request.getParameter("ids"); if(ValidateUtil.validateEmpty(ids)){ Set<Integer> gids=new HashSet<>(); Set<String> photos=new HashSet<>(); String[] result = ids.split("\\|"); for(int i=0;i<result.length;i++){ String[] temp = result[i].split(":"); gids.add(Integer.parseInt(temp[0])); photos.add(temp[1]); } GoodsBackService service=ServiceFactory.getInstance(GoodsBackServiceImpl.class); try { if(service.delete(gids)){ if(photos.size()>0){ Iterator<String> it = photos.iterator(); while(it.hasNext()){ String filePath=super.getServletContext().getRealPath("/upload/goods/")+it.next(); File file=new File(filePath); if(file.exists()){ file.delete(); } } } msg="商品删除操作成功!"; }else{ msg="商品删除操作失败!"; } } catch (Exception e) { e.printStackTrace(); } }else{ msg="删除商品的数据有误,请重新操作!"; } url="/pages/back/admin/goods/GoodsBackServlet"+referer.substring(referer.lastIndexOf("/")); request.setAttribute("msg", msg); request.setAttribute("url",url); return "/pages/forward.jsp"; } //这是删除时传递的参数:id:photo <td><input type="checkbox" name="gid" id="gid" value="${goods.gid}:${goods.photo}"/></td>
标签:date split eth text bst ase jsp else tps
原文地址:http://www.cnblogs.com/yuefeng123/p/7652315.html