• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help getting correct server path

 
Mike London
Ranch Hand
Posts: 1290
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chris Baron
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
if i get you right:
-you want to display a html table with pics
-your webpage is on your providers server
if you take realPath( path ) as src of the <img> your browser is looking for
/home/hurrican/scubapics/pics on your machine not on the server. ( locally it works because c:\etc\.. is on your machine )
normally the path from the root of your webapp should work: /scubapics/pics/jellyfish.jpg
if not, try response.encodeURL(/scubapics/pics/jellyfish.jpg)
or add your domainname ( http://www.diverMike.com/scubapics/pics/jellyfish.jpg)
hth cb
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!