Я пытаюсь загрузить файл в сервлет, используя общую загрузку apache.Но этот код List items = uploadHandler.parseRequest(request);
не выполняется, и любой код ниже этого.В чем может быть проблема?
Это мой код:
System.out.println("Start File upload");
DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
/*
* Set the size threshold, above which content will be stored on disk.
*/
fileItemFactory.setSizeThreshold(1 * 1024 * 1024); // 1 MB
/*
* Set the temporary directory to store the uploaded files of size above
* threshold.
*/
// fileItemFactory.setRepository(tmpDir);
if(ServletFileUpload.isMultipartContent(request)) {
System.out.println("Multipart");
} else {
System.out.println("Not multipart");
}
ServletFileUpload uploadHandler = new ServletFileUpload(fileItemFactory);
System.out.println("end file upload");
try {
/*
* Parse the request
*/
System.out.println("start file parse");
List items = uploadHandler.parseRequest(request);
System.out.println("start file parse2");
Iterator itr = items.iterator();
while (itr.hasNext()) {
System.out.println("Iterating");
FileItem item = (FileItem) itr.next();
/*
* Handle Form Fields.
*/System.out.println("end fileiterating");
if (item.isFormField()) {
System.out.println("form field");
System.out.println("File Name = " + item.getFieldName()
+ ", Value = " + item.getString());
} else {
// Handle Uploaded files.
System.out.println("file");
System.out.println("Field Name = " + item.getFieldName()
+ ", File Name = " + item.getName()
+ ", Content type = " + item.getContentType()
+ ", File Size = " + item.getSize());
/*
* Write file to the ultimate location.
*/
// File file = new File(destinationDir,item.getName());
// item.write(file);
}
}
} catch (FileUploadException ex) {
//System.out.println("Error encountered while parsing the request "
// + ex);
ex.printStackTrace();
} catch (Exception ex) {
//System.out.println("Error encountered while uploading file " + ex);
ex.printStackTrace();
}