How to read a file from the WAR or webapp? If I have a configuration file, say an XML file, stored inside the WAR, how do I open it from a servlet?

Alessandro A. Garbagnati

The WAR file is automatically opened by the servlet container during the startup... at least this is what the servlet specs are saying (and it is happening with both Resin and Tomcat). Once you reach the servlet just use ServletContext.getRealPath() to get the file.

For example if the file is in a 'template' dir under the root of the context, use


getRealPath("/template/file.xml"); 
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact