【发布时间】:2018-09-23 12:12:36
【问题描述】:
我创建了一个页面(比如说 query.jsp)请求过滤器,然后用户键入适当的值,然后将该值提交给 java 类。然后该类处理过滤条件,然后将结果以多个ArrayList的形式再次传递给query.jsp。我设法以对象的形式传递数据并将它们转换回 query.jsp 中的 ArrayList,但我真的不知道如何让它们迭代到每个索引中。
铸造后的产品数据样本
[GE1, T1, S1, GE1, GE4, GL1, T1, GE3, R1, GL5, E2, S6, GL5, GE1, GL1, GL5, S4, E5, S3, S6, GL6, T1, GL5, GL1, GE2, T1, R2, E1, E1, GL1, S2, S2, S6, GL3, S3, GE3, E1, S4, S3, GL2, R2, S6, S2, GL1, T4, GE2, S5, R1, GE1, S3, GL2, GE4, GL3, GE3, GL3, T3, GE5, E3, E2, T1, E2, E2, R2, GE5, GE1, GE1, GL1, GL1, GE3, T1]
施法后的每个数据都代表特定人的位置。假设product[0]的索引是针对“a”的,company[0]是针对“a”的数据,CName,validity等。
query.jsp
<input type="date" placeholder="Date from" id="datefrom" class="form-control" name="datefrom" required>
<input type="date" placeholder="Date to" id="dateto" class="form-control" name="dateto" required>
<select class="form-control" name="status" required>
<option value=""> </option>
<option value="New">New</option>
<option value="Renew">Renew</option>
</select>
<table class="table table-striped table-bordered table-hover table-full-width" id="sample_1">
<thead>
<tr>
<th>Browser</th>
<th class="hidden-xs">Creator</th>
<th>Cost (USD)</th>
<th class="hidden-xs"> Software license</th>
<th>Current layout engine</th>
</tr>
</thead>
<tbody>
<!-- START DUMPING DATA -->
<%
ArrayList<String> product = (ArrayList<String>) request.getAttribute("product");
ArrayList<String> company = (ArrayList<String>) request.getAttribute("company");
ArrayList<String> CName = (ArrayList<String>) request.getAttribute("CName");
ArrayList<String> validity = (ArrayList<String>) request.getAttribute("validity");
ArrayList<String> unit = (ArrayList<String>) request.getAttribute("unit");
ArrayList<String> totPrice = (ArrayList<String>) request.getAttribute("totPrice");
for(int i=0, i<product.size(),i++)//what size should i put index?
{%>
<tr>product</tr>
<tr>company</tr>
<tr>CName</tr>
<tr>validity</tr>
<tr>unit</tr>
<tr>totPrice</tr>
%>
【问题讨论】:
-
能否支持 Map 直到 6 个字符串?好奇
-
不,算了,哈哈,我得到了答案,所以谢谢你看到这篇文章:)
标签: java jsp for-loop arraylist