Make form parsing aware of multiple values per key for file upload forms (enctype="multipart/form-data")

This commit is contained in:
hns 2004-03-15 12:10:26 +00:00
parent b31871fdfb
commit dd4be4b6b6
2 changed files with 25 additions and 5 deletions

View file

@ -165,7 +165,12 @@ public abstract class AbstractServletClient extends HttpServlet {
String nextKey = (String) e.nextElement();
Object nextPart = parts.get(nextKey);
reqtrans.set(nextKey, nextPart);
if (nextPart instanceof List) {
reqtrans.set(nextKey, ((List) nextPart).get(0));
reqtrans.set(nextKey+"_array", ((List) nextPart).toArray());
} else {
reqtrans.set(nextKey, nextPart);
}
}
}
} catch (Exception upx) {

View file

@ -124,12 +124,27 @@ public class FileUpload {
}
}
if (filename != null) {
MimePart part = new MimePart(filename, newb, type);
Object existingValue = parts.get(name);
Object newValue = null;
parts.put(name, part);
if (filename != null) {
newValue = new MimePart(filename, newb, type);
} else {
parts.put(name, new String(newb, encoding));
newValue = new String(newb, encoding);
}
if (existingValue == null) {
// no previous value, just add new object
parts.put(name, newValue);
} else if (existingValue instanceof ArrayList) {
// already multiple values, add to list
((ArrayList) existingValue).add(newValue);
} else {
// already one value, convert to list
ArrayList list = new ArrayList();
list.add(existingValue);
list.add(newValue);
parts.put(name, list);
}
}
}