자바 온라인 도서 쇼핑 몰(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>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.