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 Access files outside the context of the Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
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
Marshal

Joined: Mar 22, 2005
Posts: 41120
    
  45
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?


Ping & DNS - my free Android networking tools app
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: 12761
    
    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
 
Similar Threads
Struts error cannot find bean
How to convert Blob Type back to File
Access is Denied
unable to downladmultiple file?
connection, pool exhausted ???