JSTL forEach的问题,从arrayList进行迭代 [英] issue of JSTL forEach iterate from arrayList
问题描述
在我的代码中,我使用了ArrayList,它在数组列表的每个索引中存储数字格式,例如'$ 0.00到$ 1,000,000.00'.通过<c:forEach>
标记在JSP中进行迭代时,
其值像
In my code, I have used ArrayList which stores the number format like '$0.00 to $1,000,000.00' in each index of array list. while iterate in JSP through <c:forEach>
tag,
its values are printing like
$ 0.00至$ 1作为第一个字符串,000作为第二个字符串,000.00作为第三字符串. 但它的打印内容必须为"$ 0.00至$ 1,000,000.00".
$0.00 to $1 as a first string, 000 as a second string and 000.00 as a thrid string. but it has to print like '$0.00 to $1,000,000.00'.
问题是什么?
预先感谢
推荐答案
您正在遍历array的元素,而不是遍历数组本身.因此,数组"$ 0.00到$ 1,000,000.00"的元素在逗号位置分割,您将获得如上所述的单个元素.
You are iterating over element of array, not over array itself. Thus the element of the array "$0.00 to $1,000,000.00" is split at comma positions and you get individual elements as you have described.
以下是一个示例:
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
java.util.ArrayList list = new java.util.ArrayList();
list.add("$0.00 to $1,000,000.00");
list.add("$1,000,000.00 to $1,000,000,000.00");
request.setAttribute("list", list);
%>
<h1>Iterating over ArrayList</h1>
<ul>
<c:forEach items="${list}" var="value">
<li><c:out value="${value}"/></li>
</c:forEach>
</ul>
<h1>Iterating over first element of ArrayList</h1>
<ul>
<c:forEach items="${list[0]}" var="value">
<li><c:out value="${value}"/></li>
</c:forEach>
</ul>
这篇关于JSTL forEach的问题,从arrayList进行迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!