gpt4 book ai didi

java - 如何在新行中打印 JSTL 迭代值

转载 作者:行者123 更新时间:2023-12-01 18:54:04 25 4
gpt4 key购买 nike

我有一个如下所示的字符串:

字符串 emps="日期1,日期2,日期3,日期4";

我的要求是使用 JSTL 标签在 jsp 页面上打印如下内容:

OutPut Should be:

日期1

日期2

日期3

日期4

我在我的jsp中使用了以下代码:

<c:set var="string2" value="${fn:split(emps,',')}" />
<c:forEach items="${string2}" var="emps1">
<td><c:out value="${emps1}"/></td>

</c:forEach>

但是我的代码正在删除“,”这个并在一行中打印如下:

date1 date2 date3 date4 

谁能给我一个解决方案,如何使用 jSTL 标签在 jsp 中逐行打印日期值?

谢谢

更新:

<c:when test="${requestScope.size!=0}">
<table border="1">
<tr>
<th>Employee Code</th>

<th>EmployeeName</th>
<th>EmployeeDepartment</th>
<th>AbsentDate</th>
<th>TotalNOOfAbsentDates</th>
</tr>


<c:forEach items="${requestScope.set1}" var="emps">
<tr>
<td><c:out value="${emps[0]}" /></td>

<td><c:out value="${emps[1]}" /></td>
<td><c:out value="${emps[2]}" /></td>

<td><c:out value="${emps[4]}" /></td>
<c:set var="string2" value="${fn:split(emps[3],',')}" />
<c:forEach items="${string2}" var="emps1">
<td>
<p><c:out value="${emps1}"/></p>

</td>

</c:forEach>

</tr>
</c:forEach>

注意:我想使用 <td> 逐行打印

这个(迭代)数据标签?

最佳答案

你的要求看起来有点奇怪,但如果你想用表格输出......

<table>
<c:set var="string2" value="${fn:split(emps,',')}" />
<c:forEach items="${string2}" var="emps1">
<tr>
<td><c:out value="${emps1}"/></td>
</tr>
</c:forEach>
</table>

我希望我正确地回答了你的问题

<小时/>

更新:

尝试运行下一个代码:

<table>
<c:set var="sourceString" value="${fn:split('q,w,e,r,t,y',',')}" />
<c:forEach items="${sourceString}" var="element">
<tr>
<td><c:out value="${element}"/></td>
</tr>
</c:forEach>
</table>

它对我来说效果很好(它输出新行中的每个字母),我确信它对你有用。检查您的 html 代码并尝试运行此代码以确保它有效。

<小时/>

upd2:

最后你的代码将如下所示:

<table border="1">
<tr>
<th>Employee Code</th>

<th>EmployeeName</th>
<th>EmployeeDepartment</th>
<th>AbsentDate</th>
<th>TotalNOOfAbsentDates</th>
</tr>


<c:forEach items="${requestScope.set1}" var="emps">
<tr>
<c:set var="string2" value="${fn:split(emps[3],',')}" />
<c:forEach items="${string2}" var="emps1">

<td><c:out value="${emps[0]}" /></td>
<td><c:out value="${emps[1]}" /></td>
<td><c:out value="${emps[2]}" /></td>
<td><c:out value="${emps1}"/></td>
<td><c:out value="${emps[4]}" /></td>

</c:forEach>
</tr>
</c:forEach>
</table>

你的错误是混合了<tr>标签智慧 <td> 。此代码将为每个缺席日期生成行,这实际上是您想要的吗?

<小时/>

upd3:如果您想仅在单元格中输出所有这些日期(看起来有点难看),请使用它:

<table border="1">
<tr>
<th>Employee Code</th>

<th>EmployeeName</th>
<th>EmployeeDepartment</th>
<th>AbsentDate</th>
<th>TotalNOOfAbsentDates</th>
</tr>


<c:forEach items="${requestScope.set1}" var="emps">
<tr>
<td><c:out value="${emps[0]}" /></td>
<td><c:out value="${emps[1]}" /></td>
<td><c:out value="${emps[2]}" /></td>
<td>
<c:set var="string2" value="${fn:split(emps[3],',')}" />
<c:forEach items="${string2}" var="emps1">
<p>
<c:out value="${emps1}"/>
</p>
</c:forEach>
</td>
<td><c:out value="${emps[4]}" /></td>
</tr>
</c:forEach>
</table>

关于java - 如何在新行中打印 JSTL 迭代值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14786957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com