How to set the path to "context path" for uploaded files using Apache Common fileupload?

Posted by BugKiller on Stack Overflow See other posts from Stack Overflow or by BugKiller
Published on 2010-05-25T04:13:20Z Indexed on 2010/05/25 4:21 UTC
Read the original article Hit count: 296

Hi,
I'm using Apache common fileupload library with Netbeans 6.8 + Glassfish.I'm trying to change the current upload path to be in the current context path of the servlet , something like this: WEB-INF/upload

so I wrote :

File uploadedFile = new File("WEB-INF/upload/"+fileName);
session.setAttribute("path",uploadedFile.getAbsolutePath());
item.write(uploadedFile);

but I notice that the library save the uploaded files into glassfish folder , here what I get when I print the absolute path of the uploaded file :

C:\Program Files\sges-v3\glassfish\domains\domain1\WEB-INF\upload\xx.rar 

My Question :

  • How can I force the common fileupload to save the uploaded file in a path relative to the current servlet path , so I don't need to specify the whole path ? is this possible ?

© Stack Overflow or respective owner

Related posts about servlets

Related posts about apache-commons