[英]How to get elements of arrayList from servlet to jsp and display on the same jsp without using AJAX
This is my servlet code 这是我的servlet代码
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 我在jsp中得到这个arralyList,我的JSP代码是
<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 当我从日期和日期给出时,它会将数据提取到arrayList中,但是以类似的格式显示它
['122131232','123232312']
I want to display them element wise on that same jsp page without using AJAX. 我想在不使用AJAX的情况下在同一个jsp页面上显示元素。
To display it element wise, use JSTL <c:forEach/>
tag, 要以元素方式显示它,请使用JSTL <c:forEach/>
标记,
<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, 要使用ajax,请使用带有Servlet和JSON的JQuery ajax,
<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>
if you only want to get length of a Collection use fn:length(tableEntity.rows))
如果你只想获取Collection的长度,请使用fn:length(tableEntity.rows))
and for the purpose of iterating use JSTL <c:forEach>
并且为了迭代使用JSTL <c:forEach>
<c:forEach items='${List}' var='varObj'>
<c:out value="${varObj}"/>
</c:forEach>
Hope this will help. 希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.