jQuery in Action, 2nd edition*
The moose likes Servlets and the fly likes Create directories while uploading files in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Create directories while uploading files in Servlet" Watch "Create directories while uploading files in Servlet" New topic
Author

Create directories while uploading files in Servlet

Neeraj Dheer
Ranch Hand

Joined: Mar 30, 2005
Posts: 225
Hi!

I am required to upload files using my web application. Using a servlet for this. And using Apache Commons - FileUpload (My favourite is the O' Reilly Multipart, but cant use it because of licensing issues).

Problem:

The file upload works fine as long as i try to upload to directories already present, but if the directories are not present and i try to create the directories, i get an 'Access Denied' Exception.

Here is the code:



and the Exception is:



Yep, i know, not the best of codes, but am concerned with the Exception at the moment.

Should i separate the tasks of making the directories and then writing to them in 2 different servlets? Will that work??
[ October 06, 2005: Message edited by: Neeraj Dheer ]
Neeraj Dheer
Ranch Hand

Joined: Mar 30, 2005
Posts: 225
sorry...my mistake...bug in the code...was trying to open a directory with FileOutputStream, not a file...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Create directories while uploading files in Servlet
 
Similar Threads
Errors
can we make response from a child thread of a servlet?
java.rmi.MarshalException: Exception occurred in server thread; nested
Where can I get any info on Websphere 6.1?
Test Connection failed ( IBM Websphere 5.1 Express )