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 .
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.
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, CIW Certified Ecommerce specialist
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 :