File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Creating Directories using Servlet outside the web app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Creating Directories using Servlet outside the web app" Watch "Creating Directories using Servlet outside the web app" New topic
Author

Creating Directories using Servlet outside the web app

J Das
Ranch Hand

Joined: Jul 27, 2011
Posts: 83

hello to all , please help me in creating directories using servlet outside the web app . creating directories inside the web app is not a good idea as recommended by many . whenever the application is clean and build again , the directories and files inside it gets deleted (which is not safe) . So i would like to know how can we do it outside the application. I have done it inside the web application for which the code is shown below. The code below is a servlet which gets executed when a link is clicked ( this link is a user account confirmation link ) . when the user clicks the link , the below servlet runs , and when this servlet runs the account of that user is activated. A folder gets created for every user on successful activation of their accounts .


This particular code ....

creates a directory inside the web app with the username as the directory name.. I want to do this , but somewhere outside the web app. Please show me what should i do .
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 484

J Das wrote:
creates a directory inside the web app with the username as the directory name.. I want to do this , but somewhere outside the web app. Please show me what should i do .


Do you have trouble with using absolute path? Why don't you use absolute path, for example C:\userdir, D:\userdir...


PM Me If You Want to get Urgent Help on Java Programming
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1000
    
    1

I guess using Absolute path should work for you to save/create new directory outside web application.

If you have migrate your application to different machines/enivornments (either Windows or Linux) , then I would suggest you hard code the absolute path as key value pair in some properties file in your web application.
for eg -


Then read this key value runtime in your Servlet and append username to this path. So if username is 'testUser' then full path becomes C://UserHomeDirectory/testUser. Now use your directory creation code to create new directory.

~ abhay






Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I
J Das
Ranch Hand

Joined: Jul 27, 2011
Posts: 83

Do you have trouble with using absolute path? Why don't you use absolute path, for example C:\userdir, D:\userdir...



I did this ..it is working fine ? but i want to know is there any proper alternative solutions ?



and after creating this directory , i need to upload files to this directory .. For every user registration, a directory will be created , and when the user logs in , that user can upload files to his directory . The code for uploading to respective directory is shown below :



Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 484

J Das wrote:


I did this ..it is working fine ? but i want to know is there any proper alternative solutions ?




It should work fine, as long as you have total control of the server.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating Directories using Servlet outside the web app
 
Similar Threads
Problem With Download File Servlet
saving file path from servlet in mysql
Problem in running session beans
web service integration using Netbeans IDE
Servlet File Upload and JQuery as his brothers