我有一个网格,用户从中选择行,当单击一行时,它的 id 将发送到我的操作类AddBookToSession.java
,然后将列表返回到我的 jsp 页面invoice.jsp
java.util.ConcurrentModificationException
当用户从我的网格中选择一行时, 我收到错误。
我读了这个类似的问题,但我仍然无法解决我的问题。
我的问题是:为什么我收到java.util.ConcurrentModificationException
错误以及如何解决这个问题。请帮我解决这个问题。
控制台错误:
Dec 10, 2012 11:37:30 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819)
at java.util.ArrayList$Itr.next(ArrayList.java:791)
at org.apache.struts2.components.IteratorComponent.end(IteratorComponent.java:334)
at org.apache.struts2.views.jsp.IteratorTag.doAfterBody(IteratorTag.java:87)
-------------------
------------------
发票.jsp
<s:if test="#session['BOK'].size() > 0">
<table width="100%" class="userTable" valign="top" border="0">
<s:iterator value="#session.BOK" status="userStatus">
<tr class="<s:if test="%{#userStatus.odd == true}">odd</s:if> <s:else>even</s:else>">
<td width="80%"><s:property value="bookTitile" /></td>
<td align="right" width="20%">
<s:url id="cancelURL" action="RemovebooksFromSession" namespace="/admin/setups/secure/jspHomepage/bookstransaction">
<s:param name="bkid" value="%{id}"></s:param>
</s:url>
<sj:a href="%{cancelURL}" targets="myAdvanceDivBoxx">Rem</sj:a></td>
</tr>
</s:iterator>
</table>
</div>
</s:if>
AddBookToSession.java
public String execute()
{
String bookid = request.getParameter("bid");
String qnty=dao.getquantityById(Integer.parseInt(bookid));
if(qnty.equals("0")||qnty.equals("")||qnty.equals("null")){
return SUCCESS;
}
Bookdetails book = dao.listBookDetailsById(Integer.parseInt(bookid));
books = (ArrayList) session.get(BillTransactionBooksConstants.BOK);
if ( books == null ) books = new ArrayList<Bookdetails>();
boolean already_exists = false;
for ( Bookdetails b : books )
{
if ( Integer.toString(b.getId()).equals(bookid))
{
already_exists = true;
break;
}
}
if (book != null && !already_exists )
{
books.add(book);
System.out.println("books size"+books.size());
session.put(BillTransactionBooksConstants.BOK,books);
}
return SUCCESS;
}