#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    7
    Rep Power
    0

    Session Problems(ConcurrentModificationException)


    Hi,

    I am facing some problems with session here.
    I get a java.util.ConcurrentModificationException whenever i try to empty the shopping cart.

    Could somebody pls kindly advise?

    Thanks in advance

    below is the code:
    <% String item = request.getParameter("itemName");
    if(item != null && item.equals("emptyCart")) {
    java.util.Enumeration attributeNames = session.getAttributeNames();
    while(attributeNames.hasMoreElements()) {
    String attributeName = (String)attributeNames.nextElement();
    session.removeAttribute(attributeName);
    }
    } else if(item != null) {
    String attributeName = item + "CD";
    session.setAttribute(attributeName, item);
    }
    %>
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    1
    Rep Power
    0

    Lightbulb Solution


    Hi,

    Simple but functions;
    1# all enumerations in a vector;
    2# trim vector
    3# iterate vector with removeAttribute();

    Enumeration enum = session.getAttributeNames();

    Vector enumV= new Vector();
    while( enum.hasMoreElements() ){
    enumV.add( enum.nextElement().toString() );
    }

    enumV.trimToSize();

    for( int i = 0; i < enumV.size(); i++ ){
    session.removeAttribute( enumV.get( i ).toString() );
    }


    Tricae

IMN logo majestic logo threadwatch logo seochat tools logo