Jsp c:forEach迭代
以下是我正在尝试的粗略迭代:Jsp c:forEach迭代,jsp,jstl,Jsp,Jstl,以下是我正在尝试的粗略迭代: <c:forEach items="${row.myList}" var="mainRow" varStatus="table"> ${ table.first? '<table>':'<tr><td><strong>${mainRow.heading}</strong></td></tr>'} <c:forEach it
<c:forEach items="${row.myList}" var="mainRow" varStatus="table">
${ table.first? '<table>':'<tr><td><strong>${mainRow.heading}</strong></td></tr>'}
<c:forEach items="${mainRow.values}" var="value" >
<tr>
<td><input type="checkbox" value="${value}"/>${value}</td>
</tr>
</c:forEach>
${ table.last? '</table>':''}
</c:forEach>
${table.first?'':'${mainRow.heading}'}
${value}
${table.last?'':'}
问题是它打印${mainRow.heading}而不是属性值。
表中还有哪些其他选项。?像第一个,最后一个。有关于它的文档吗?${table.first?'':'${mainRow.heading}'}
${ table.first? '<table>':'<tr><td><strong>${mainRow.heading}</strong></td></tr>'}
上面的表达式不是您想要的,因为您在EL表达式中的字符串文本中嵌入了EL表达式。你想要的是
${table.first? '<table>' : '<tr><td><strong>' + mainRow.heading + '</strong></td></tr>'}
${table.first?'':''+mainRow.heading+''}
或
${mainRow.heading}
在您的代码片段中,'${mainRow.heading}'
对于JSP来说只是一个字符串,因此不需要替换。用这个代替
${ table.first? '<table>':'<tr><td><strong>'.concat(mainRow.heading).concat('</strong></td></tr>') }
${table.first?'table':''.concat(mainRow.heading).concat('')}
(我不得不使用html实体来避免不匹配的标记。)
其他varStatus选项记录在此处:在El中,您有一个选项让isFirst或isLast检查第一个和最后一个元素,为了更好地理解,+
是否适用于El中的字符串连接?还有,为什么您在不匹配的元素等方面没有问题?感谢您的解决方案,第二个解决方案有效且更具可读性。此外,如果您可以提出更多建议,现在显示的复选框仅在一列中。我们可以连续有两个复选框吗。我正在尝试各种与begin、end、step的组合……我直接在jsp中进行了更改(在部署路径中),效果很好。我现在正在工作区中更改,我的RAD显示行中的错误,并没有结束标记。类似的错误。如何消除这样的错误?@Dhananjay:您的编辑器很困惑,因为HTML标记不平衡,但重要的是生成的HTML是有效的。
${ table.first? '<table>':'<tr><td><strong>'.concat(mainRow.heading).concat('</strong></td></tr>') }