Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File Upload

 
ford Darcy Jr
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using com.oreilly.servlet.MultipartRequest for uploading files in servlets. But when my application is moved to a weblogic server...file upload doesnt work, it gives a error: "Not a directory" in weblogic, but works just fine in servlets. Do I need to change something for it to work while on weblogic server ?

Thanks.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you setting the location on the drive for the uploaded files?
 
ford Darcy Jr
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben,

The path is ../folder1/folder2. Folder2 being the folder to which the files get uploaded.

Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So your locating the folder by looking in folders relative to the current working directory from where the JVM was invoked?
Is this directory inside the webapp?
Can you post the code that locates the directory?
 
ford Darcy Jr
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben,

Thanks for the immediate reply. This directory is in my web app.

Heres the code in servlets:
MultipartRequest multi =
new MultipartRequest(request, "../folder1/folder2", 10 * 1024 * 1024,
new com.oreilly.servlet.multipart.
DefaultFileRenamePolicy());

This works perfectly in servlets. But when I move it to the weblogic server...its not working. The path on the weblogic server where the program is running with an error "Not a directory" is: http://folderone/foldertwo/folderthree/folder1/folderfive/folder6 wherein folder6 is the java program name and folder1 corresponds to the foldername (folder1) listed in my java program.

I hope it helps.

Thanks.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using an absolute path for the directory.
While your at it, make it a directory that isn't inside the web app -- at least initially.

Finding files on the local system with relative paths is always risky.
You're counting on the current working directory of the JVM always being the same.

Also, if your app server is configured to run the app as a packed war file (without unpacking to an exploded file system), you will not be able to write to directories within the app.

Your best bet is to always use an absolute path that is configured as a servlet or context init param, with the directory being outside of the webapp. Write a servlet that streams the files if you need to access them again for downloading.

Try with an absolute path and let us know if it helps.

-Ben
 
ford Darcy Jr
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben,

Thanks a lot for the detailed explanation. I will try to use an absolute path.

Thanks.
 
ford Darcy Jr
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When I am using an absolute path on the weblogic server, I am getting this error: "Error 500--Internal Server Error
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
The server encountered an unexpected condition which prevented it from fulfilling the request". What does this mean...does it have to do anything with weblogic configuration or got to do with my java file upload application. The same program works just fine on my Java server.

Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your absolute path pointing to a directory within your webapp?
 
ford Darcy Jr
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben,

Thanks for the response. Yes, the absolute path is pointing to a directory in my web application. Please let me know where I am going wrong.

Thanks for all the help.
 
ford Darcy Jr
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I would like to know if Multipart Request file upload is not compatible on weblogic servers. My upload application works fine on Java platform but not when migrated to weblogic server. Any suggesstions ?

Thanks,
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ford Darcy Jr:
Hi Ben,

Thanks for the response. Yes, the absolute path is pointing to a directory in my web application. Please let me know where I am going wrong.

Thanks for all the help.


Is your web application running as a packed war file or as an exploded file system?
 
ford Darcy Jr
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Now my code works fine even on Weblogic. I just had to set the path right.

Thanks.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad it's working,
Thanks for posting back the results.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic