我的formData包含一个文件
喜欢:
var files = document.getElementById("uploadfile").files;
/* Create a FormData instance */
var formData = new FormData();
/* Add the file */
var file = files[0];
alert(file.name);
formData.append('uploadfile', file, file.name);
client.open("POST", "fileupload?q="+uploadfile,true);
client.setRequestHeader("Content-Type", "multipart/form-data");
client.send(formData); /* Send to server */
现在我想在我的servlet fileupload中使用这个表单数据。如何使用它们?请帮忙。
答案 0 :(得分:0)
我举一个例子,我在项目中如何处理它。我使用doPost函数来获取它。
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
Do whatever you want with that item.
}