• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Creating Directories using Servlet outside the web app

 
Ranch Hand
Posts: 83
MS IE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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




 
J Das
Ranch Hand
Posts: 83
MS IE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 530
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic