错误:java.util.ConcurrentModificationException [英] Error : java.util.ConcurrentModificationException
问题描述
我有一个网格从用户选择行的地方,
当一行被点击,然后它的id发送到我的行动类 AddBookToSession.java
和之后病毒它返回一个列表到我的jsp页面 invoice.jsp
我得到错误 java.util.ConcurrentModificationException
,当用户从我的网格中选择一行。
我读了这个类似的问题,但是我仍然无法解决我的问题。
我的问题是:为什么我得到 java.util.ConcurrentModificationException
错误,我怎样才能解决这个问题。请帮我解决这个问题。
控制台出错: invoice.jsp AddBookToSession.java 异常堆栈跟踪指向你的jsp中的 查看您的代码并尝试确定是否有可能在您的jsp页面正在构建时运行其他代码。 用您发布的代码无法帮助您。 i have a grid from where users select the row ,
when a row is clicked then its id is sending to my action class I am getting error I read this similar question ,But still i am not able to solve my problem. My problem is : Why i am getting Error in console: invoice.jsp AddBookToSession.java
The exception stack trace points to the Take a look at your code and try to determine if it is possible that other code runs while your jsp page is being build. Cannot help you more with the code you posted. 这篇关于错误:java.util.ConcurrentModificationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
<$ p $ org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE:servlet jsp的Servlet.service()抛出异常
java。 util.ConcurrentModificationException java.util.ArrayList
$ Itr.checkForComodification(ArrayList.java:819)$ b $ 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)
--- ----------------
------------------
< s:if test =#session ['BOK']。size()> 0>
< table width =100%class =userTablevalign =topborder =0>
< s:iterator value =#session.BOKstatus =userStatus>
< tr class =< s:if test =%{#userStatus.odd == true}> odd< / s:if>< s:else>偶< / s:else> ;>
< td width =80%>< s:property value =bookTitile/>< / td>
< td align =rightwidth =20%>
< s:url id =cancelURLaction =RemovebooksFromSessionnamespace =/ admin / setups / secure / jspHomepage / bookstransaction>
< s:param name =bkidvalue =%{id}>< / s:param>
< / s:url>
< sj:a href =%{cancelURL}targets =myAdvanceDivBoxx> Rem< / sj:a>< / td>
< / tr>
< / s:iterator>
< / table>
< / div>
< / s:if>
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;
(Bookdetails b:books)
{
if(Integer.toString(b.getId())。equals(bookid))
{
already_exists = true ;
break;
$ b $ if(book!= null&&!already_exists)
{
books.add(book);
System.out.println(books size+ books.size());
session.put(BillTransactionBooksConstants.BOK,books);
}
返回SUCCESS;
s:iterator
是抛出异常的地方。这意味着,当元素通过书单时,另一段代码将从列表中添加或删除。这可能是您的Java代码或其他(例如 RemovebooksFromSession
)。
AddBookToSession.java
and after wards it is returning a list into my jsp page invoice.jsp
java.util.ConcurrentModificationException
,when users selects a row from my grid. java.util.ConcurrentModificationException
Error and how can I solve this issue. Please help me to solve this problem. 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)
-------------------
------------------
<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>
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;
}
s:iterator
in your jsp being the place where the exception is thrown. That means that while that element goes through the book list another piece of code adds or removes from the list. That could be your Java code, or some other (e.g. RemovebooksFromSession
).