File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Different results for ServletContext.getRealPath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Different results for ServletContext.getRealPath " Watch "Different results for ServletContext.getRealPath " New topic

Different results for ServletContext.getRealPath

Reginald Law

Joined: Jan 21, 2004
Posts: 19
I noticed that JRun tags on a file path seperator for the method ServletContext.getRealPath, where as Apache Tomcat does not append it on. I am calling the method from the init method in the servlet.

How does one get around this so code does not have to be changed from one application server to another one ?

SCJP 1.4
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

The following code (which has not been compiled or tested) assumes that all your other code *expects* your paths to end with /.
I agree. Here's the link:
subject: Different results for ServletContext.getRealPath
It's not a secret anymore!