I have a String like below:
String emps=”date1,date2,date3,date4″;
My requirement is to print like below on a jsp page using JSTL tags:
OutPut Should be:
date1
date2
date3
date4
I have used the below code in my jsp:
<c:set var="string2" value="${fn:split(emps,',')}" />
<c:forEach items="${string2}" var="emps1">
<td><c:out value="${emps1}"/></td>
</c:forEach>
But my code is removing “,” this and printing like below in a single line:
date1 date2 date3 date4
Could any one give me a solution that ,how to print the date values line by line in a jsp using jstl tags?
thanks
Update:
<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>
Note:
I want to print
this(Iteration) data line by line using <td> tag?
Your requirements looks little strange, but if you want to output it with table…
I hope I got your question correctly
upd:
Try to run next code:
It works fine for me (it outputs each letter in new row) and I sure that it would work for you. Check out your html code and try to run this code to be sure, that it works.
upd2:
Finally your code would look like this:
Your mistake was to mix
<tr>tags wits<td>. This code would generate row for each absent date, is it actually what you want?upd3:
If you want to output all this dates in only cell (it looks little ugly), use it: