I have found that ServletContext.getRealPath() doesn't seem to handle
relative paths correctly.  It appears to simply prepend the docroot onto
what ever string you pass it.  This isn't very helpful if I need to get to a
file in the requests directory and I don't know where it is.

Given a directory structure like:
/DOCROOT/dirA/dirB/dirC/test.jsp

With test.jsp like:

<%
String virtualPath = "This is a load of Bull.";
ServletContext servletContext = pageContext.getServletContext();
String realPath  = servletContext.getRealPath(virtualPath);
out.println("Virtual Path: '"+virtualPath+"' is located at:
'"+realPath+"'<p>");
%>

Gives me:

Virtual Path: 'This is a load of Bull.' is located at: '/DOCROOT/This is a
load of Bull.'

If this is a spec issue then who do I talk to to get it changed?  As it
stands now I don't think there is a way to figure out what directory a jsp
is run in.

Thanks for you time.

Cavan Morris
Systems Analyst
Prime Advantage

Reply via email to