我上传了我input type="file"
在我的网络应用程序中浏览的文件。问题是我得到的FileItem
列表大小为 0 虽然我可以在下面看到所有上传的文件信息
request
-> JakartaMutltiPartRequest
-> 文件属性
这是读取文件的java代码
public InputStream parseRequestStreamWithApache(HttpServletRequest request)
throws FileUploadException, IOException {
InputStream is = null;
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = upload.parseRequest(request);
// here the item size is 0 ,i am not sure why i am not getting my file upload in browser with type="file"
// but If inspect request in debugger i can see my file realted info in request--->JakartaMutltiPartRequest----->files attribute
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (!item.isFormField()) {
is = item.getInputStream();
}
}
return is;
}
编辑:
这是JSP部分:
<form NAME="form1" action="customer/customerManager!parseRequestStreamWithApache.action" ENCTYPE="multipart/form-data" method="post" >
<TABLE >
<tr>
<th>Upload File</th>
<td>
<input name="fileUploadAttr" id="filePath" type="file" value="">
</td>
<td >
<Input type="submit" value ="uploadFile"/>
</td>
</tr>
</TABLE>
</form>