This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts file path problem

 
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";
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic