<c:foreach>同时遍历两个list的方法

本文介绍了一种在项目中同步遍历两个列表的方法,并通过示例代码展示了如何使用JSP和c:forEach标签来实现这一功能。具体地,示例展示了如何在网页上显示购物车列表(cartList)和商品列表(proList)中的对应项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目中遇到一个问题 。需要同时从两个list中取值。经过百度找到了解决办法。

cartList  proList都是从后台传来的值


<c:forEach items="${cartList }" var="cart" varStatus="loop">
<tr class="active">
<td width="60" width="40%">
<input type="hidden" name="id" value="22">
<img src="${pageContext.request.contextPath}/${proList[loop.count-1].pimage }" width="70" height="60">
</td>
<td width="30%">
<a target="_blank"> ${proList[loop.count-1].pname }</a>
</td>
<td width="20%">
${proList[loop.count-1].shopPrice }
</td>
<td width="10%">
<input type="text" name="quantity" value="${cart.count }" maxlength="4" size="10">
</td>
<td width="15%">
<span class="subtotal">${cart.price }</span>
</td>
<td>
<a href="javascript:;" class="delete">删除</a>
</td>
</tr>
</c:forEach>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值