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 a file from WEB-INF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "creating a file from WEB-INF" Watch "creating a file from WEB-INF" New topic
Author

creating a file from WEB-INF

nikil shar
Ranch Hand

Joined: May 25, 2008
Posts: 116
hi all,
am writing a servlet which is meant to pass a file into another system. its a static file so i have put it inside my 'WEB-INF' directory but for some reason the code can not instantiate the file.



the code doesnt get inside the if statement since it fails at the if statement check to see if file exists. is there something wrong with my code ??

ta.
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 645
Have a look at ServletContext.getResourceAsStream("...").
Sony Agrawal
Ranch Hand

Joined: Oct 04, 2009
Posts: 143
Is it possible to access a file using such a path??
I mean a path where in "WEB-INf " is present ??
File f = new File("/WEB-INF/test.afp");
If that is the case then can't someone illegally access the class files if they know the server location and project name

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5


Implies an absolute path starting with /WEB-INF - look into the ServletContext getRealPath() method.

Note that if you create a file under /WEB-INF the servlet container can NOT serve it directly, you will have to provide a servlet which can access that directory.

Bill
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 645
sony agrwal wrote:Is it possible to access a file using such a path??
I mean a path where in "WEB-INf " is present ??
File f = new File("/WEB-INF/test.afp");
If that is the case then can't someone illegally access the class files if they know the server location and project name



Your servlet can access content under /WEB-INF, the web container cannot.
Sony Agrawal
Ranch Hand

Joined: Oct 04, 2009
Posts: 143
Thanks for the reply people..

So as i understand the bottom line is,"The only way to access the contents of the WEB-INF directory is only through the servlet"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: creating a file from WEB-INF