2012-09-18 44 views
0

下面每次画廊只增加1个产品我点击添加到购物车,我希望它通过ID为所选的特定项目从<foreach tag>

问题: 1 - 该servlet加1个产品加入购物车(第一个)和URL看起来像这样: 本地.../DisplayCart的productId = 01 &的productId = 02 &行动= addtocart

<form action="/DisplayCart"> 
<c:forEach var="product" items="${products}"> 
        <tr> 
         <td>${product.name}</td> 
         <td>${product.description}</td> 
         <td>${product.price}</td> 
         <td></td> 
         <td> 
          <input type="hidden" name="productId" value="${product.id}"> 
          <input type="submit" name="action" value="addtocart"></td> 
        </tr> 
       </c:forEach> 

     <form action="<c:url value='/DisplayCart'/>"> 
     <table> 
      <c:forEach var="item" items="${cart.items}"> 
        <tr> 
         <td> 
     <input type="hidden" name="productId" value="${item.product.id}"> 
     <input type="text" size="2" name="quantity" value="${item.quantity}"> 
          <input type="submit" value="Update"> 
         </td> 
         <td>${item.product.name}</td> 
         <td>${item.product.description}</td> 
         <td>${item.product.price}</td> 
       <td><input type="submit" name="removeButton" value="Remove">  </td> 
        </tr> 
      </table> 
       </form> 
      </c:forEach> 
+0

没有其实我是想用户是能够选择任何这个循环基本上从数据库中列出的项目..无论如何感谢 – TrackmeifYouCan

回答

0

,我发现它的很大一部分。

替换此

 <td><input type="submit" name="removeButton" value="Remove">  </td> 

与此

 <td><a href="<c:url value='/DisplayCart?productId=${product.id}'/>">add</a></td> 

和URL始终显示为/ DisplayCart?productId参数= XX

happyyy

+0

在同一时间,我会感谢有人解释为什么它不是以前的方式工作?即使removeButton也只是删除第一个。 – TrackmeifYouCan