• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access files outside the context of the Servlet

 
Bageshwar Pratap Narain
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic