|Subject:||RE: getRealPath("/") and getRealPath("")|
|From:||Brett Bergquist (bber...@snet.net)|
|Date:||Jan 2, 2001 3:57:43 pm|
Craig, you mention that a container is not required to run your web application out of filesystem, but could run it out of a JAR, etc. and mention to use getResource and getResourceAsStream. Now I do this for anything that I need read-only support, but what if a web application needs read-write support for things such as data files, etc. I would prefer that these files be part of the installed web application. What would a container do in these cases.
Thanks for your insight.
Brett M. Bergquist
-----Original Message----- From: Craig R. McClanahan [mailto:Crai...@eng.sun.com] Sent: Tuesday, January 02, 2001 5:08 PM To: tomc...@jakarta.apache.org Subject: Re: getRealPath("/") and getRealPath("")
chris monster wrote:
apologies if i have missed a previous posting in my searches.
in cross-testing our webapp between Tomcat 3.1 and another container (Resin 1.2.1) for compliance, i noticed that the behaviour of ServletContext.getRealPath() is different when applied to the application root. ( actually, after checking the 2.2 spec, i suspect this may not be well defined. )
for getRealPath("/") AND getRealPath("")
Tomcat 3.1 returns:
whereas the other container returns:
(without the trailing path-separator)
i'm coding around this difference right now, but i'm curious who i should be bugging about this. (get it, 'bugging'? ;)
Since this would be a spec interpretation issue, the best place to send "bugging" messages would be to the spec feedback address printed on the front of the servlet spec:
Tomcat (and every other container) should implement what the spec says. If the spec is silent on a particular issue, then the appropriate thing to do would be lobby for clarification in the next version -- which is timely now, because the Servlet 2.3 spec is currently in "proposed final draft" stage, not "final".
PS: As a side issue, I would encourage web app developers to start using ServletContext.getResource() and ServletContext.getResourceAsStream(), instead of ServletContext.getRealPath() followed by file I/O, to access internal resources. The reason for this is that a servlet container is *not* required to run your web app out of a filesystem (as Tomcat currently does) -- it may run them directly from a JAR file, or in an environment like Oracle's where the web app's resources are actually BLOB objects stored in a database, rather than being accessible as files.