• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

creating a file from WEB-INF

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at ServletContext.getResourceAsStream("...").
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic