用java编程,模拟网上购物(结算)
结算联系到好几个文件哦。上上个星期我们刚把网上购物车系统做完。下面是Servlet里的一段,希望对你有用!
else if (command.equalsIgnoreCase("modifybookcount")) {
int bookCartID = (Integer) session.getAttribute("bookcartID");
int operBookID = Integer.valueOf((String) request
.getParameter("operBookID"));
// 获得购物车中原有数量
int bookCount = Integer.valueOf((String) request
.getParameter("bookCount"));
// 获得需要会员修改的数量
int operBookCount = Integer.valueOf((String) request
.getParameter("operBookCount"));
// 得到图书数量增量
int bookCountIncrement = operBookCount - bookCount;
// 得到图书价格的增量
double bookPriceIncrement = bookCountIncrement
* Double.valueOf((String) request.getParameter("disPrice"));
CartListDAO cartlist = new CartListDAO();
// 更新购物车中图书的总数量和总价格
cartlist
.updateBookCount(bookCartID, operBookID, bookCountIncrement);
BookCartDAO bookcart = (BookCartDAO) session
.getAttribute("bookcart");
bookcart.updateCartData(bookCartID, bookPriceIncrement,
bookCountIncrement);
targetPage = "/cartlist.jsp";
RequestDispatcher dispatcher = request
.getRequestDispatcher(targetPage);
dispatcher.forward(request, response);
}