81,122
社区成员




package sh.shop.web.servlet.manager;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import sh.shop.domain.Product;
import sh.shop.exception.ListProductException;
import sh.shop.service.ProductService;
@WebServlet("/listProduct")
/**
* 后台
* 查询所有商品信息的servlet
*/
public class ListProductServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
// 1.创建service层的对象
ProductService service = new ProductService();
// 2.调用service层的listAll()
List<Product> list = service.listAll();
// 3.将查询出的所有商品放进request域中
request.setAttribute("list", list);
// 4.将请求转发到list.jsp
request.getRequestDispatcher("/admin/products/list.jsp").forward(
request, response);
return;
} catch (ListProductException e) {
e.printStackTrace();
response.getWriter().write(e.getMessage());
return;
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
}
<tbody>
<c:forEach items="${list}" var="p">
<tr class="text-c va-m">
<td><input name="" type="checkbox" value=""></td>
<td>${p.id }</td>
<td><a onClick="" href="javascript:;"><img width="60" class="product-thumb" src=""></a></td>
<td class="text-l"><a style="text-decoration:none" onClick="" href="javascript:;">${p.name }</a></td>
<td class="text-l">${p.description }</td>
<td>${p.price }</td>
<td>${p.category }</td>
<td class="td-manage"><a style="text-decoration:none" class="ml-5" onClick="product_edit('产品编辑','product-add.html','10001')" href="javascript:;" title="编辑"><i class="Hui-iconfont"></i></a> <a style="text-decoration:none" class="ml-5" onClick="product_del(this,'10001')" href="javascript:;" title="删除"><i class="Hui-iconfont"></i></a></td>
</tr>
</c:forEach>
</tbody>
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// 1.创建service层的对象
ProductService service = new ProductService();
// 2.调用service层的listAll()
List<Product> list = service.listAll();
// 3.将查询出的所有商品放进request域中
request.setAttribute("list", list);
// 4.将请求转发到list.jsp
request.getRequestDispatcher("/admin/products/list.jsp").forward(
request, response);
}