I haven´t found any answer in the forum, however it's possible the question has yet been asked. Sorry in advance, if that's the case.
Basically, I'm creating a FormData object in a jsp to capture an uploaded file and I would like to access it in my java Dispatcher. I tried the type FormData in java, but it looks like it doesnt exist.
Any help would be appreciated.
Here is the .jsp code:
var file_data = $("#fileUpload").prop("files")[0];
var file_name = $("#fileUpload").val();
var form_data = new FormData();
form_data.append("file", file_data);
form_data.append("fileName", file_name);
$.post('crearNuevaActa.action',
{
processData: false,
contentType: false,
data: form_data,
}
First convert your formData to JSON
var myFormData = JSON.stringify(form_data);
on your jQuery post change data to:
data: "data:"+data,
On your action class include following,
private List<MyBean> data;
//setter and getter
Define MyBean POJO class;
class MyBean{
//include file filename and any other field you have
//getter setter
}
configure your action class to deserialize JSON
<action name="" class="">
<result type="json"/>
<interceptor-ref name="json">
<interceptor-ref name="defaultStack">
</action>