hello i wrote a servlet which print a gif picture that is under the "c:\cart\images\",if i specify the absolute path,it works well,but i want to use the relative path,i don't know the initial path(or base path) of the servlet,"%tomcathome%/bin" or "%tomcathome%/webapps"?who can tell me.i think it should be "../../cart/images",but it don't work!why? thank you!
Hi there. William, I noticed your comment about not writing code which uses the current servlet path - why is this? I usually store this value in a class parameter in the init() method, and it works fine for me. Am I missing something?
<B>daniel.walker</B><BR><I>***bleed in your own light...<BR>...dream of your own life...***</I>
Author and all-around good cowpoke
Joined: Mar 22, 2000
The "current" directory of the JVM running the servlet engine depends on how it was started and the vendor's conventions. What works for Tomcat may not work for JRun, etc etc. Bill
William, but I believe the original poster was asking about the root directory of the web app (zb, correct me if that's not true -- that's what I was assuming with my answer re getRealPath()), rather than the cwd of the JVM. That path should be safe to use if you need the directory path to the current web app tree. No? bear
Joined: Jan 14, 2002
yes,i want to know the web root directory,i find that the tomcat use "%tomcathome%/webapps" as its webroot,but the "%tomcathome%/bin" as the reference directory to classpath,but all of above come from my guess,i can't find any official document to verify it,in jchq website,bill have told me that the tomcat start from "%tomcathome%/bin",as follow link: http://www.jchq.net/discus/messages/50028/50538.html?1011185788 my detailed scenario is : my web directory is "%tomcathome%/webapps/cart",there is a servlet which access a gif file that is under the "../images" directory,in the servlet, i specify "/cart/images/xx.gif",the servlet works well,this fact seem like to tell me the "%tomcathome%/webapps" is the webroot reference.
but after i move my "cart" directory to "c:/",and modify "server.xml" to map the web to "c:/cart",the web still work,but the problem appear to the picture file,how to specify the path to the picture in the servlet? no doubt, the "/cart/images" don't work,because i believe the web root is "%tomcathome/webapps%",but what confused me is that the "../../cart/images.xx.gif" DON'T work too,why?it seem like that "webapps" is not the web root,it contradict to my belief. if i specify the absolute path as "c:/cart/images/xx.gif",it works.how can i specify the relative path?what's the reference path?"bin" or "webapps" or neither of them?the path problem in tomcat nearly drive me crazy! so that the better way is to define the reference root by MYSELF as bill said! thanks