Reputation: 1723
This is my servlet code
con.getCliWithProp(fromdate, todate, packageid, quantity,pro);
for(int i=0;i<Integer.parseInt(quantity);i++){
results.add(con.resultCli.toArray()[i].toString());
}System.out.println(results);
request.setAttribute("cli",results);
}
request.getRequestDispatcher("/npt.jsp").forward(request, response);
}
I am getting this arralyList in a jsp, and my JSP code is
<form action="getDetails" method="post">
<label>From date</label>
<input type="text" name="fromDate" placeholder="From Date" id="datepicker">
<label>To date</label>
<input type="text" name="toDate" placeholder="To Date" id="datepicker1">
<br>
<button class="btn btn-success" id='submit' >Generate CLI</button>
</form>
<br><br>
<div id="display">
<pre>
<font size="4">${requestScope.cli}</font>
</pre>
</div>
when I give from date and to date, it fetches me the data in an arrayList but displays it in the format like
['122131232','123232312']
I want to display them element wise on that same jsp page without using AJAX.
Upvotes: 0
Views: 4074
Reputation: 333
if you only want to get length of a Collection use fn:length(tableEntity.rows))
and for the purpose of iterating use JSTL <c:forEach>
<c:forEach items='${List}' var='varObj'>
<c:out value="${varObj}"/>
</c:forEach>
Hope this will help.
Upvotes: 1
Reputation: 21961
To display it element wise, use JSTL <c:forEach/>
tag,
<div id="display">
<pre>
<c:forEach items=${requestScope.cli} var="item">
<font size="4">${item}</font> <br />
</c:forEach>
</pre>
</div>
To use ajax, use JQuery ajax with Servlet and JSON,
<script>
$(document).ready(function() {
$('#button').click(function() {
$.get('JsonStrListServlet', function(responseJson) {
// Parse the json result on somediv
var $ul = $('<ul>').appendTo($('#somediv'));
$.each(responseJson, function(index, item) {
$('<li>').text(item).appendTo($ul);
});
});
});
</script>
Upvotes: 1