wood burning stoves 2.0
The moose likes Servlets and the fly likes Access files outside the context of the Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Java » Servlets
Bookmark "Access files outside the context of the Servlet" Watch "Access files outside the context of the Servlet" New topic
Author

Access files outside the context of the Servlet

Bageshwar Pratap Narain
Greenhorn

Joined: Mar 04, 2009
Posts: 24
I want to access files which are outside the webapps directory.
My OS is windows/linux and I have a scenario, wherein, i need to write files, to specific directories, outside webapps.
Tomcat throws a Security Exception, so how do I get away with this.



Bageshwar.Pratap.Narain
OCJP
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42954
    
  73
Sounds like Tomcat is running with a security manager that disallows access to that file. Does the account Tomcat is run under allow access to that file, and to all directories above it?
veda bandaru
Greenhorn

Joined: Sep 14, 2006
Posts: 3
Hi,

Could you post the code where you are trying to access the file.

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12888
    
    5
For security, servlet containers are prohibited from serving directly files outside the context. Tomcat's "default" servlet handles file requests such as css and image requests but obeys this prohibition.

The solution is simple, you must provide your own servlet implementation that gets the image request, knows where to look for (for example) image files, creates the correct headers, and send the data.

Bill

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Access files outside the context of the Servlet