Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing a file under WEB-INF using getResource()

 
chandan kumar mitwaa
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a file under WEB-INF folder named a.txt

In may Servlet code MyServlet.java i use:

getServletContext().getResource("/WEB-INF/a.txt");

it evaluates to null.

But as SRV.9.5 notes:


The WEB-INF node is not part of the public document tree of the application. No file contained in the WEB-INF directory may be served directly to a client by the container. However, the contents of the WEBINF directory are visible to servlet code using the getResource and getResourceAsStream method calls on the ServletContext, and may be exposed using the RequestDispatcher calls. Hence, if the Application Developer needs access, from servlet code, to application specific configuration information that he does not wish to be exposed directly to theWeb client, he may place it under this directory.

Why what is the problem???
 
raj malhotra
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Chandan

I am able to get the value as




My servlet code:



So just check if you have placed that file directly under WEB-INF or in WEB-INF/classes.Also make sure that a.txt is deployed properly to the server.
 
chandan kumar mitwaa
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raj,

Will you please send me the war file
 
chandan kumar mitwaa
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Raj,
I got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic