1

I'm using GWT widget to upload my files, I'd like to upload them under tomcat folder on Ubuntu server, so I need to set the param value for this piece of code in web.xml:

<context-param> 
    <description>Location to store uploaded file</description> 
    <param-name>file-upload</param-name> 
    <param-value>
         ...
     </param-value> 
</context-param>

If I try to set http://ip.ip.ip.ip:8080/var/lib/tomcat7it returns UploadActionException and e.getMessage()="http://ip.ip.ip.ip:8080//var//lib//tomcat7". It seems that Eclipse try to search this path in my Window filesystem. Any ideas to resolve this? Thanks.

django
  • 153
  • 1
  • 5
  • 19

1 Answers1

1

http://ip.ip.ip.ip:8080/var/lib/tomcat7 is not the same thing as /var/lib/tomcat7 on your server. To use that as the upload directory put this init-param in your upload servlet declaration in web.xml

<context-param> 
    <description>Upload Directory</description> 
    <param-name>upload-directory</param-name> 
    <param-value>/var/lib/tomcat7</param-value> 
</context-param>

and then in the upload servlet build a path string starting with

String dirPath = getServletContext().getInitParameter("upload-directory"); 

then write the FileItem to a file like this

File file = new File( dirPath + "/" + fileItem.getName());
fileItem.write(file);

All of this would require the whole directory /var/lib/tomcat7 to be writable by whatever user tomcat is running under which is a bad idea. But there you have it.

bhowden
  • 669
  • 7
  • 15
  • If I use */var/lib/tomcat7*, it creates the folders under C://var/lib/tomcat7 in my Window file system. Tomcat is on another ip unbuntu server and not on my pc. – django Sep 24 '14 at 07:49
  • Thanks @bhowden, I had no permission under this folder and it wasa bad idea to write there! Anyway the problem was also that from window the path was wrong an it runs only when the webapp was deployed under ubuntu. – django Sep 24 '14 at 16:46