Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletContect and getRealPath() from a WAR file

 
David Follow
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I use getServletContext().getRealPath(sConfig); to get the real path of a file with my Tomcat structure. This works fine in a straight Tomcat environment. However, If I build a WAR file and deploy it, it doesn't work, no surprise, since it says so in the Sun API-Javadoc. But what do I do so that I can optain the real path if I deploy my web application in a WAR file?
TIA, Detlef
 
Stephane Nicoll
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand your question, but I've had the same problems when using Jar files for my applications. Do not forget the leading / for searching your file relating to your web app context.
Hope it helps,
St�phane
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's strongly recommended that you don't use "getRealPath" in your web applications. Sure Tomcat expands wars out to real files, but there are several servers which run your application straight from a war file.
All servers should provide a temporary working directory to each web application, to use when you need to store things (uploaded files, temporary configs etc.), and you should load other files using getResource()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic