// 添加购物车标签:product,hibernate3,int,price,cart,struts1,new,网购,productId From: https://blog.51cto.com/javaalpha/5893239
if("add".equals(type))
{
ProductService pService = new ProductService();
// 产品信息
int productId = Integer.parseInt(req.getParameter("productId"));
int count = 1;
float price = Float.parseFloat(req.getParameter("price"));
// 查询
Product p = pService.selectById(productId);
Set<Product> product = new HashSet<Product>();
product.add(p);
Cart cart = new Cart();
cart.setProduct_id(product); // 这里总是提示是null 异常 这是设置添加商品的商品ID
cart.setCount(count);
cart.setSum(price);
service.insert(cart);
}