I have a multipart/form-data form with some <input type='text'>
and <input type='file'>
fields.
I use this code
List<FileItem> multipartItems = null;
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (!isMultipart) {
System.out.println("false");
} else {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
multipartItems = null;
try {
multipartItems = upload.parseRequest(request);
System.out.println("true "+multipartItems.toString());
} catch (FileUploadException e) {
e.printStackTrace();
}
}
to find out if the form has multipart content. Then, I use
Map<String, String[]> parameterMap = new HashMap<String, String[]>();
for (FileItem multipartItem : multipartItems) {
if (multipartItem.isFormField()) {
processFormField(multipartItem, parameterMap);
} else {
request.setAttribute(multipartItem.getFieldName(), multipartItem);
}
}
By running the first snippet of code, the else is executed, but at the end multipartItems is null.
For this reason, the for in the second code snippet is never executed.
I don't know why there is this behaviour. I'm using Struts 1.3.10
EDIT
How can I check if struts has already parsed the request?
If so, is there a way to turn off it only for a particular form?
EDIT 2
I have a dynamic form, coded in json format. I have a form bean for json and for hidden properties. Then I parse the json "by hand". All works perfectly, but now I have to add input type=file fields and use the multipart/form-data enctype.
To prevent struts request parsing I put in the web.xml:
<init-param>
<param-name>multipartClass</param-name>
<param-value>none</param-value>
</init-param>
But it doesn't seem to work