I am trying to upload multiple files from jsp using below code:
When I execute it from my local machine I am able to upload in the local systems folder.
But when I access the same from remote machine I am expecting that the files should be uploaded to the same machine where my tomcat exist ,but I get error C:\Files\`folder/file not found`.
Please guide.How to upload it in remote machine or where the tomcat resides
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (!isMultipart) {
} else {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = null;
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
e.printStackTrace();
}
Iterator itr = items.iterator();
while (itr.hasNext()) {
FileItem item = (FileItem) itr.next();
if (item.isFormField()) {
} else {
try {
String itemName = item.getName();
File savedFile = new File("C:\\Files\\a.tiff");
item.write(savedFile);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
This is the path where I want to upload all files C:\\Files\\ of the machine where tomcat is.
Change your file save path to
new File("C:\\Files\\");. Even, still you have any problem, then create one folder withFilesname in another driveEorFwhatever and change your code likenew File("E:\\Files\\");if you wanna save your file toEdrive.Note: Since,
Cdrive is the primary drive in windows OS, so due to lack of permission, it won’t allow to create new file/folder in that drive. So, please try the alternative solution. I mean try to change your file location.