Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Struts file path problem  RSS feed

 
Dave Hendler
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to figure out how access an XML file with FileReader somewhere in my webapps's directory without resorting to absolute file paths. Is there a way to have a custom config file in, say, WEB-INF and be able to load that without specifying the full path?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the ServletContext object's getRealPath() method to find the actual path for a given virtual path. So, to get the actual path for your context root, you'd code the following in your Actoin class:

String contextPath = getServlet().getServletContext().getRealPath("/");

Once you have that, you can get any other path relative to it. For example:

String webInfPath = contextPath + "/WEB-INF";
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!