コード例 #1
0
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String id = request.getParameter("id");
    BusinessService service = new BusinessServiceImpl();
    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);
    response.sendRedirect(request.getContextPath() + "/client/listcart.jsp");
  }
コード例 #2
0
  private void getAll(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    List list = service.getAllCategory();
    request.setAttribute("categories", list);
    request.getRequestDispatcher("/manager/listcategory.jsp").forward(request, response);
  }
コード例 #3
0
 private void add(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   try {
     Category c = WebUtils.request2Bean(request, Category.class);
     c.setId(UUID.randomUUID().toString());
     service.addCategory(c);
     request.setAttribute("message", "Ìí¼Ó³É¹¦");
   } catch (Exception e) {
     e.printStackTrace();
     request.setAttribute("message", "Ìí¼Óʧ°Ü");
   }
   request.getRequestDispatcher("/message.jsp").forward(request, response);
 }