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 Reading static files with servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Reading static files with servlets" Watch "Reading static files with servlets" New topic
Author

Reading static files with servlets

JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
Hi all,
I got a web application (ear/war file) deployed on Was 4.
I want to read a static file (.txt) from a servlet, but I don't want this static file to be directly accessible from an URL.
1)According to your experience, what is the best place to put this static file ? A sub Directory of the context-root ? or of Web-inf ?
2)I planned to put it as a sub directory of the context-root. Then, how can I "reach it" the servlet. I would like to use only relative URL.
3)Last but definitively not least question, how can I secure this folder with my static file in order to prevent a user from seing it ?
Thanks in advance for your precious contribution.


/ JeanLouis<br /><i>"software development has been, is, and will remain fundamentally hard" (Grady Booch)</i><br /> <br />Take a look at <a href="http://www.epfwiki.net/wikis/openup/" target="_blank" rel="nofollow">Agile OpenUP</a> in the Eclipse community
JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
Hi all.
The only solution I found to my problem is the following :
(Load a static file from a servlet into an object property)
String propPath = getServletContext().getResource("/WEB-INF/myPropFolder/myProp.props").toString();
/* I have to cut the 6 first characterrs which are "file:/"*/
/* and I don't know why these ccharacteres are here
propPath = propPath.substring(6,propPath.length());
Properties props = new Properties();
prop.load(new FileInputStream(path));

Does this solution make sense for you ?
Any better one to suggest me ??
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

WEB-INF is not browsable, unless your servlet runner is broken. So placing files in this directory will hide them.

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Reading static files with servlets