校园二手物品交易平台实现购买商品的功能
该功能是购买者进行购买的功能。购买者可以查看物品信息、留言信息以及物品的评价,填写购买的数量,就可以把物品放到购物车内。后台程序:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
request.setCharacterEncoding("UTF-8");
List<ProductBean> list = (List<ProductBean>)request.getSession().getAttribute("list");
if(list==null){
list = new LinkedList<ProductBean>();
}
//System.out.println(request.getParameter("id")+"---"+request.getParameter("number"));
ProductBean b = new ProductBean(request.getParameter("id"),request.getParameter("number"));
list.add(b);
request.getSession().setAttribute("list", list);
response.sendRedirect("index");
}
运行结果:购买者填写购买信息,填写数量即可,否则失败。