You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Till Nagel <ti...@net-eye.de> on 2001/03/01 21:11:39 UTC

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 ?