자바 온라인 도서 쇼핑 몰(5)카 트 모듈 2

먼저 효과 보기:

결산 하 다
list.jsp

<form id="jieSuanForm" action="<c:url value='/CartItemServlet'/>" method="post">
 <input type="hidden" name="cartItemIds" id="cartItemIds"/>
 <input type="hidden" name="total" id="hiddenTotal"/>
 <input type="hidden" name="method" value="loadCartItems"/>
</form>
function jiesuan() {
 // 1.            id,     
 var cartItemIdArray = new Array();
 $(":checkbox[name=checkboxBtn][checked=true]").each(function() {
 cartItemIdArray.push($(this).val());//            
 });
 // 2.      toString(),       cartItemIds  hidden
 $("#cartItemIds").val(cartItemIdArray.toString());
 //      ,       
 $("#hiddenTotal").val($("#total").text());
 // 3.       
 $("#jieSuanForm").submit();
}
servlet

public String loadCartItems(HttpServletRequest req, HttpServletResponse resp)
 throws ServletException, IOException {
 /*
 * 1.   cartItemIds  
 */
 String cartItemIds = req.getParameter("cartItemIds");
 double total = Double.parseDouble(req.getParameter("total"));
 /*
 * 2.   service  List<CartItem>
 */
 List<CartItem> cartItemList = cartItemService.loadCartItems(cartItemIds);
 /*
 * 3.   ,     /cart/showitem.jsp
 */
 req.setAttribute("cartItemList", cartItemList);
 req.setAttribute("total", total);
 req.setAttribute("cartItemIds", cartItemIds);
 return "f:/jsps/cart/showitem.jsp";
}
Dao
여러 개의 CartItem 불 러 오기

public List<CartItem> loadCartItems(String cartItemIds) throws SQLException {
 /*
 * 1.  cartItemIds     
 */
 Object[] cartItemIdArray = cartItemIds.split(",");
 /*
 * 2.   wehre  
 */
 String whereSql = toWhereSql(cartItemIdArray.length);
 /*
 * 3.   sql  
 */
 String sql = "select * from t_cartitem c, t_book b where c.bid=b.bid and " + whereSql;
 /*
 * 4.   sql,  List<CartItem>
 */
 return toCartItemList(qr.query(sql, new MapListHandler(), cartItemIdArray));
}

showitem.jsp

<c:choose>
 <c:when test="${empty cartItemList }">  ~</c:when>
 <c:otherwise>
 <form id="form1" action="<c:url value='/OrderServlet'/>" method="post">
  <input type="hidden" name="cartItemIds" value="${cartItemIds }"/>
  <input type="hidden" name="method" value="createOrder"/>
  <table width="95%" align="center" cellpadding="0" cellspacing="0">
  <tr bgcolor="#efeae5">
   <td width="400px" colspan="5"><span style="font-weight: 900;">    </span></td>
  </tr>
  <tr align="center">
   <td width="10%"> </td>
   <td width="50%">    </td>
   <td>  </td>
   <td>  </td>
   <td>  </td>
  </tr>
 
  <c:forEach items="${cartItemList }" var="cartItem">
  <tr align="center">
   <td align="right">
   <a class="linkImage" href="<c:url value='/jsps/book/desc.jsp'/>"><img border="0" width="54" align="top" src="<c:url value='/${cartItem.book.image_b }'/>"/></a>
   </td>
   <td align="left">
   <a href="<c:url value='/jsps/book/desc.jsp'/>"><span>${cartItem.book.bname }</span></a>
   </td>
   <td>¥${cartItem.book.currPrice }</td>
   <td>${cartItem.quantity }</td>
   <td>
   <span class="price_n">¥<span class="subtotal">${cartItem.subtotal }</span></span>
   </td>
  </tr>
  </c:forEach>
  
  <tr>
   <td colspan="6" align="right">
   <span>  :</span><span class="price_t">¥<span id="total">${total }</span></span>
   </td>
  </tr>
  <tr>
   <td colspan="5" bgcolor="#efeae5"><span style="font-weight: 900">    </span></td>
  </tr>
  <tr>
   <td colspan="6">
   <input id="addr" type="text" name="address" value="                  1          "/>
   </td>
  </tr>
  <tr>
   <td style="border-top-width: 4px;" colspan="5" align="right">
   <a id="linkSubmit" href="javascript:$('#form1').submit();">    </a>
   </td>
  </tr>
  </table>
 </form>
 </c:otherwise>
</c:choose>

좋은 웹페이지 즐겨찾기