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 create a directory under the servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "create a directory under the servlet" Watch "create a directory under the servlet" New topic
Author

create a directory under the servlet

Mike Phillip
Ranch Hand

Joined: Dec 05, 2007
Posts: 37
is it possible to create a directory under the web-inf folder?

I'm to create a directory at the moment a user registers:

say login: john

than creates: web-inf/users/john

I'm using:
File newDir = new File(servlet.getServletContext().getRealPath("/WEB-INF/users/")+userDAO.getLogin()+"/");

but it does't create, when I change the dir to outside the web-inf it acepts

if its not possible, how can I create the dirs without exposing them?

thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Does the WEB-INF/users directory already exist?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

Originally posted by Mike Dikta:
is it possible to create a directory under the web-inf folder?
There is no web-inf folder; it's WEB-INF.

This is not advised. What happens if your app needs to be redeployed from its war? You should create such folders outside the bounds of the web application.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mike Phillip
Ranch Hand

Joined: Dec 05, 2007
Posts: 37
Originally posted by Bear Bibeault:
There is no web-inf folder; it's WEB-INF.

This is not advised. What happens if your app needs to be redeployed from its war? You should create such folders outside the bounds of the web application.


and how can I protect it?


thanks guys, problem solved
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Mike Dikta:
and how can I protect it?

If it's not inside the webapp's directory stucture, it will not be directly accessible to the web.

thanks guys, problem solved

What it was?
Mike Phillip
Ranch Hand

Joined: Dec 05, 2007
Posts: 37
Originally posted by Ben Souther:

What it was?


File newDir = new File(servlet.getServletContext().getRealPath("/WEB-INF/users//")+userDAO.getLogin()+"/")

I put an extra "/"
 
Don't get me started about those stupid light bulbs.
 
subject: create a directory under the servlet