【发布时间】:2012-02-25 01:09:30
【问题描述】:
我正在使用 JSTL 来显示我从数据库中搜索到的 JSP 中的记录。
例如,从数据库返回的这些记录是:
<tr>
<td class="leavehistory">2012-01-31 18:16:36.0</td><td class="leavehistory">Present</td>
</tr>
<tr>
<td class="leavehistory">2012-01-31 18:16:38.0</td><td class="leavehistory">Present</td>
</tr>
这是我的 JSP:
<c:forEach items="${attendRecord}" var="attendRecord">
<tr>
<td class="leavehistory">${attendRecord.attendDt}</td><td class="leavehistory">${attendRecord.status}</td>
</tr>
</c:forEach>
这是我的 Servlet:
ArrayList<Attendance> arrSub = new ArrayList<Attendance>();
while (rs.next()){
Attendance att = new Attendance();
att.setAttendDt(rs.getString(1));
att.setStatus(rs.getString(2));
att.setClsType(rs.getString(3));
att.setSubID(rs.getString(4));
arrSub.add(att);
}
request.getSession().setAttribute("attendRecord", arrSub);
在我执行另一个搜索的地方,结果将是这样的:
<tr>
<td class="leavehistory">2012-01-31 18:16:36.0</td><td class="leavehistory">Present</td>
</tr>
<tr>
<td class="leavehistory">2012-01-31 18:16:38.0</td><td class="leavehistory">Present</td>
</tr>
<tr>
<td class="leavehistory">2012-01-31 18:16:36.0</td><td class="leavehistory">Late</td>
</tr>
<tr>
<td class="leavehistory">2012-01-31 18:16:38.0</td><td class="leavehistory">Late</td>
</tr>
这是我用来调用我的 servlet 的代码:
<script>
function reviewAtt(){
var f = document.review;
f.hdSearch.value = f.cardID.value +";"+document.getElementById("clsType").value+";"+document.getElementById("sub").value;
f.method = "POST";
f.target = "_self";
f.action = "../build/web/WEB-INF/classes/leave/searchAttendServlet";
f.submit();
}
</script>
然后我继续执行另一个搜索动作,最新的搜索结果应该替换旧记录并显示最新的结果。但它不会,最新的结果将添加到旧记录的下面。我只想显示最新的搜索结果。 旧的搜索结果将被淘汰。
有什么办法可以解决这个问题吗?
【问题讨论】:
-
你没有说明你是如何在
arrSub中设置数据的 -
它在我的代码中,我只是误将它粘贴在这里。对不起。
-
如果您正在创建新的
ArrayList并添加每个请求,那么它不应该附加搜索结果,请添加更多详细信息如何调用 servlet -
我已经更新了调用servlet的代码。
标签: java html jsp servlets jstl