In my
JSP code trying to get server paths I get very different results running this code on
Tomcat and on the real web server.
I'm trying to build a table of images and need to be able to refer to where the images are based on the server directories (starting at the web root of the application I believe).
When I run the local code and the server code, the paths are different as you would expect, but locally the code works and on the web server, it doesn't: I get too much path inforamtion on the server.
I'm trying to get path information like this:
String servletPath = request.getServletPath();
String rootSite = servletPath.substring(1,servletPath.lastIndexOf("/")+1);
String pathToPics = getServletContext().getRealPath(rootSite+"pics");
out.println("<p>"+pathToPics + "<p>");
out.println(rootSite);
Locally (development machine), this prints:
C:\Program Files\Apache\Tomcat 4.1\webapps\ROOT\scubapics\pics
scubapics/
** OK **
However, on the web server it prints:
/home/hurrican/public_html/scubapics/pics
scubapics/
*NOT OK*
For some reason the paths above are referring to part of the server I can't even see (the /home/hurrican part).
Needless to say, with incorrect paths, my table of JPG files don't display at all.
Is there a better way of getting server paths that will work regardless? I also tried getServletContext(), but that didn't work.
Also, is it possible something isn't set up correctly on the web server? This is a new web server account.
Thanks much for anyone's input, ideas, etc.
-- Mike