Java 访问JSP标记内的会话数组变量
我想访问JSP标记中的JSP会话数组值。我能够使用下面的代码在JSTL标记中创建它Java 访问JSP标记内的会话数组变量,java,jsp,session,jstl,Java,Jsp,Session,Jstl,我想访问JSP标记中的JSP会话数组值。我能够使用下面的代码在JSTL标记中创建它 <c:forEach var="cartItem" items="${cart.cartItems}" varStatus="counter"> <div class="each_amt_shwtot"> <div class="eachamtshw_nametot" align="left"><h4>${cartI
<c:forEach var="cartItem" items="${cart.cartItems}"
varStatus="counter">
<div class="each_amt_shwtot">
<div class="eachamtshw_nametot" align="left"><h4>${cartItem.partNumber}</h4></div>
<div class="eachamtshw_qty"><h4>${cartItem.quantity}</h4></div>
<div class="eachamtshw_price"><h4>${cartItem.unitCost} LKR</h4></div>
</div>
</c:forEach>
输出为“lk.company.app.webapp.beans”。CartBean@1608fae”
有人能为上述JSTL提供等效的JSP代码吗?
<%
List<CartItem> cartItemsList = (List<CartItem>) session.getAttribute("cart");
for(CartItem cartItem : cartItemsList) { %>
<div class="each_amt_shwtot">
<div class="eachamtshw_nametot" align="left"><h4><%=cartItem.getPartNumber()%></h4></div>
<div class="eachamtshw_qty"><h4><%=cartItem.getQquantity()%></h4></div>
<div class="eachamtshw_price"><h4><%=cartItem.getUnitCost()%> LKR</h4></div>
</div>
<% } %>
LKR
可能您可以相应地修改此代码,但我假设您已经在会话中存储了CartItem列表,因此使用上述代码您可以获取Cart Items列表并对其进行迭代Array[]carItems=(Array[])session.getAttribute(“Cart”);
Array[] carItems = (Array[])session.getAttribute("cart");
for(CarItem caritem: carItems){
%>
<div class="each_amt_shwtot">
<div class="eachamtshw_nametot" align="left"><h4><%= caritem.getPartNumber() %></h4></div>
<div class="eachamtshw_qty"><h4><%= caritem.getQuantity() %></h4></div>
<div class="eachamtshw_price"><h4><%= caritem.getUnitCost() %> LKR</h4></div>
</div>
<% }%>
适用于(CarItem CarItem:carItems){
%>
LKR
您是否仍在使用c标记?您是否仍有不好的设计可以移回scriptlet。请尝试添加一个小说明,说明您认为此解决方案最适合回答原始问题的原因,谢谢。不起作用,请查看更新的问题。.我正在尝试使用JSP标记访问会话值,因为我想验证并将该值写入文本文件。
<div class="eachamtshw_price"><h10>${cart.orderTotal} LKR</h10></div>
String group=session.getAttribute("cart").toString();
<%
List<CartItem> cartItemsList = (List<CartItem>) session.getAttribute("cart");
for(CartItem cartItem : cartItemsList) { %>
<div class="each_amt_shwtot">
<div class="eachamtshw_nametot" align="left"><h4><%=cartItem.getPartNumber()%></h4></div>
<div class="eachamtshw_qty"><h4><%=cartItem.getQquantity()%></h4></div>
<div class="eachamtshw_price"><h4><%=cartItem.getUnitCost()%> LKR</h4></div>
</div>
<% } %>
Array[] carItems = (Array[])session.getAttribute("cart");
for(CarItem caritem: carItems){
%>
<div class="each_amt_shwtot">
<div class="eachamtshw_nametot" align="left"><h4><%= caritem.getPartNumber() %></h4></div>
<div class="eachamtshw_qty"><h4><%= caritem.getQuantity() %></h4></div>
<div class="eachamtshw_price"><h4><%= caritem.getUnitCost() %> LKR</h4></div>
</div>
<% }%>