struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Schachter, Michael" <MSchach...@Bluestone.com>
Subject RE: Bug in handling multiple values in multipart forms
Date Thu, 01 Mar 2001 20:18:17 GMT
Till,

Thanks, I'll include this with the other patch I'm working on to improve the
speed of multipart requests.

-----Original Message-----
From: Till Nagel [mailto:till.nagel@net-eye.de]
Sent: Thursday, March 01, 2001 3:12 PM
To: struts-user@jakarta.apache.org
Subject: Bug in handling multiple values in multipart forms


Hi,

I've encountered a bug in handling multipart requests.
(last nightly build 20010224)

If a form is sent with enctype="multipart/form-data" the multiple values
(e.g. <select multiple...>) aren't set correctly. In the
DiskMultipartRequestHandler the values are stored in a Hashtable thus only
the last one of the values is set in the Form.

A possible solution:

old DiskMultiPartRequestHandler.java @ line 71

if (!element.isFile())

  textElements.put(element.getName(), element.getValue());
  allElements.put(element.getName(), element.getValue());
}

---

new DiskMultiPartRequestHandler.java

if (!element.isFile())

 String name = element.getName();
 String value = element.getValue();

 Object oldValue = textElements.get(name);
 if (oldValue != null) {
   String[] oldValues = new String[1];

   try {
     oldValues = (String[]) oldValue;
   } catch (ClassCastException e) {
     oldValues[0] = (String) oldValue;
   }
   int length = oldValues.length;

   String[] newValue = new String[length + 1];
   for (int i = 0; i < length; i++) {
     newValue[i] = oldValues[i];
   }
   newValue[length] = value;

   textElements.put(name, newValue);
   allElements.put(name, newValue);

 } else {
   textElements.put(name, value);
   allElements.put(name, value);
 }
}



Regards,
Till

P.S. Any hints to
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg02713.html ?




Mime
View raw message