import java.io.IOException
import java.io.PrintWriter
import javax.servlet.ServletException
import javax.servlet.http.HttpServlet
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import ssc.domain.Book
import ssc.domain.Cart
import ssc.service.BusinessService
//完成书籍购买
public class BuyServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String id = request.getParameter("id")
BusinessService service = new BusinessService()
Book book = service.findBook(id)
//添加用户的购物车
Cart cart = (Cart) request.getSession().getAttribute("cart")
if (cart==null)
{
cart = new Cart()
request.getSession().setAttribute("cart", cart)
}
//把书加入到购物车,完成购买
cart.add(book)
request.getRequestDispatcher("/WEB-INF/jsp/listcart.jsp").forward(request, response)
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doGet(request, response)
}
}
这是我写的购物车
网上这样的模板很难找吗?应该很容易找到才对啊,就几个html页面的源代码,网上多的是!去站长之家看看吧,都是免费的素材!只不过大多数都是英文的模板,你下载后估计还得自己修改为中文!有点耗时间,不过模板还不赖,支持响应式!