Tôi tải lên tệp mà tôi duyệt bằng input type="file"
trong ứng dụng web của tôi. Vấn đề là tôi nhận được kích thước danh sách FileItem
là 0 mặc dù tôi có thể thấy tất cả các thông tin tập tin được tải lên dướiTải tệp lên bằng parseRequest của ServletFileUpload?
request
->JakartaMutltiPartRequest
-> file thuộc tính
Đây là mã java mà đọc file
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;
}
EDIT:
đây là JSP phần:
<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>
đăng jsp của bạn tại đây –
Mã biểu mẫu HTML của bạn là gì? –
Đã đăng mã jsp/html quá –