Need help with exception: ConcurrentModificationException<br>!_NEWLINE_!when trying to modify a Session
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Friday, June 21, 2002 07:39 AM

I am rather new to this and trying to learn JSPs. With help from a book, I made a small JSP that adds some attributes to the session object. If I try to remove the attributes, I get an exception. Can anybody help? The code is: <% // Selektion abfragen String artikel = request.getParameter("artikelName"); // Falls selektiert, Einkaufswagen in Session leeren if (artikel != null) { if (artikel.equals("wagenLeeren")) { Enumeration attributeNames = session.getAttributeNames(); while (attributeNames.hasMoreElements()) { String attributeName = (String)attributeNames.nextElement(); session.re   More>>

I am rather new to this and trying to learn JSPs.

With help from a book, I made a small JSP that adds some attributes to
the session object.

If I try to remove the attributes, I get an exception.

Can anybody help?


The code is:

			
<% // Selektion abfragen
String artikel = request.getParameter("artikelName");
// Falls selektiert, Einkaufswagen in Session leeren
if (artikel != null) {
if (artikel.equals("wagenLeeren")) {
Enumeration attributeNames = session.getAttributeNames();
while (attributeNames.hasMoreElements()) {
String attributeName = (String)attributeNames.nextElement();
session.removeAttribute(attributeName);
}
} else {
// Sonst Artikel zwischenspeichern
String attributeName = "CD_" + artikel;
session.setAttribute(attributeName, artikel);
}
}
%>


The error occurs when I try to do the "removeAttribute".

The error messages are:

			
java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.next(HashMap.java:736)
at org.apache.catalina.util.Enumerator.nextElement(Enumerator.java:166)
at org.apache.jsp.CDs$jsp._jspService(CDs$jsp.java:112)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
at java.lang.Thread.run(Thread.java:484)


Any ideas?
Richard

   <<Less

Re: Need help with exception: ConcurrentModificationException<br>!_NEWLINE_!when trying to modify a Session

Posted By:   Deepayan_Roy  
Posted On:   Tuesday, June 25, 2002 02:30 AM

Replace your code with this


<% // Selektion abfragen
String artikel = request.getParameter("artikelName");
// Falls selektiert, Einkaufswagen in Session leeren
if (artikel != null) {
if (artikel.equals("wagenLeeren")) {
java.util.Vector vec = new java.util.Vector();
Enumeration attributeNames = session.getAttributeNames();
while (attributeNames.hasMoreElements()) {
String attributeName = (String)attributeNames.nextElement();
vec.addElement(attributeName);
}
for (int i=0;i String attributeName = (String)vec.elementAt(i);
session.removeAttribute(attributeName);
}
} else {
// Sonst Artikel zwischenspeichern
String attributeName = "CD_" + artikel;
session.setAttribute(attributeName, artikel);
}
}
%>


Let me know if it helped.
About | Sitemap | Contact