朋友们,你们有过这样的经历吗?在页面上写入一个 <c:forEach items="${categories}" var="category">,然后,你刷新一次以后,它就会把上次显示的东西在下面再显示一遍!你重复刷新几次,它就会在下面出现几遍原来的结果,弄的我一头雾水,还望各位能帮助一下.
我是通过<a href="../category.do?action=categorySearch" target="mainFrame">商品类别|添加|修改|删除 访问我的action,然后,转到我的显示页面.
然后,我再点击这个链接或是刷新当前页面,都会使其原来的数据再写入一遍,我的页面显示为:
<c:forEach items="${categories}" var="category">
<tr>
<th scope="row"> <c:out value="${category.id}"></c:out> </th>
<th scope="row"><c:out value="${category.name}"></c:out> </th>
<th scope="row"><c:out value="${category.descr}"></c:out> </th>
<th scope="row"><c:out value="${category.pid}"></c:out> </th>
<th scope="row"><c:out value="${category.grade}"></c:out> </th>
</tr>
</c:forEach>
action如下:
public ActionForward categorySearch(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List l = null;
l = cm.search();
System.out.println("action:" + l.size());
if(!l.isEmpty()) {
request.setAttribute("categories", l);
return mapping.findForward("categoryshow");
}
return mapping.findForward("error");
}
那位朋友能帮一下忙啊!
我是通过<a href="../category.do?action=categorySearch" target="mainFrame">商品类别|添加|修改|删除 访问我的action,然后,转到我的显示页面.
然后,我再点击这个链接或是刷新当前页面,都会使其原来的数据再写入一遍,我的页面显示为:
<c:forEach items="${categories}" var="category">
<tr>
<th scope="row"> <c:out value="${category.id}"></c:out> </th>
<th scope="row"><c:out value="${category.name}"></c:out> </th>
<th scope="row"><c:out value="${category.descr}"></c:out> </th>
<th scope="row"><c:out value="${category.pid}"></c:out> </th>
<th scope="row"><c:out value="${category.grade}"></c:out> </th>
</tr>
</c:forEach>
action如下:
public ActionForward categorySearch(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List l = null;
l = cm.search();
System.out.println("action:" + l.size());
if(!l.isEmpty()) {
request.setAttribute("categories", l);
return mapping.findForward("categoryshow");
}
return mapping.findForward("error");
}
那位朋友能帮一下忙啊!
System.out.println("the size is "+l.size);