Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > URGENT! Please help! Access files through absolute path

Reply
Thread Tools

URGENT! Please help! Access files through absolute path

 
 
javadev
Guest
Posts: n/a
 
      11-05-2006
Hello

I have a java based web application deployed on Apache Tomcat.

On one of my JSP pages, I try to display an image, the path of which is
an absolute path (say, C:\somePic.jpg) pointing to a location on the
server on which the application is deployed. However when I try to
access this web page from a different machine, it looks for this image
file on the local machine and not the server. How can I specify an
absolute path but still make sure that the jsp page is picking up the
image from the server and not the local machine on which it is being
run?

Thanks
Swetha

 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      11-05-2006
javadev wrote:
....
> I have a java based web application deployed on Apache Tomcat.
>
> On one of my JSP pages, I try to display an image, the path of which is
> an absolute path (say, C:\somePic.jpg) pointing to a location on the
> server on which the application is deployed. However when I try to
> access this web page from a different machine, it looks for this image
> file on the local machine and not the server. How can I specify an
> absolute path but still make sure that the jsp page is picking up the
> image from the server and not the local machine on which it is being
> run?


Uh-huh.. well, to fix that, simply... wait (checks sub.)

Sub: URGENT! ....

Oh.. (checks watch) apparently I'm too late.
Never mind.

























[ Look into ServletContext.getRealPath() ]

Andrew T.

 
Reply With Quote
 
 
 
 
javadev
Guest
Posts: n/a
 
      11-05-2006
Thanks Andrew

How can I get a handle to the servletcontext object?

Swetha

Andrew Thompson wrote:
> javadev wrote:
> ...
> > I have a java based web application deployed on Apache Tomcat.
> >
> > On one of my JSP pages, I try to display an image, the path of which is
> > an absolute path (say, C:\somePic.jpg) pointing to a location on the
> > server on which the application is deployed. However when I try to
> > access this web page from a different machine, it looks for this image
> > file on the local machine and not the server. How can I specify an
> > absolute path but still make sure that the jsp page is picking up the
> > image from the server and not the local machine on which it is being
> > run?

>
> Uh-huh.. well, to fix that, simply... wait (checks sub.)
>
> Sub: URGENT! ....
>
> Oh.. (checks watch) apparently I'm too late.
> Never mind.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> [ Look into ServletContext.getRealPath() ]
>
> Andrew T.


 
Reply With Quote
 
javadev
Guest
Posts: n/a
 
      11-05-2006
I figured I can use application.getRealPath coz application is of type
ServletContext.

Thanks
Swetha


Andrew Thompson wrote:
> javadev wrote:
> ...
> > I have a java based web application deployed on Apache Tomcat.
> >
> > On one of my JSP pages, I try to display an image, the path of which is
> > an absolute path (say, C:\somePic.jpg) pointing to a location on the
> > server on which the application is deployed. However when I try to
> > access this web page from a different machine, it looks for this image
> > file on the local machine and not the server. How can I specify an
> > absolute path but still make sure that the jsp page is picking up the
> > image from the server and not the local machine on which it is being
> > run?

>
> Uh-huh.. well, to fix that, simply... wait (checks sub.)
>
> Sub: URGENT! ....
>
> Oh.. (checks watch) apparently I'm too late.
> Never mind.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> [ Look into ServletContext.getRealPath() ]
>
> Andrew T.


 
Reply With Quote
 
javadev
Guest
Posts: n/a
 
      11-05-2006
Ok, what happens now when I use application.getRealPath(absPath) where
absPath is a string that contains the absolute path of the file (say,
C:\somePic.jsp) is that the absolute path just gets appended to the
path of the application on the server so it ends up as "C:\Program
Files\Tomcat\webapps\myApp\C:\somePic.jpg which still does not work.
Any ideas on what I can do to fix this?


Andrew Thompson wrote:
> javadev wrote:
> ...
> > I have a java based web application deployed on Apache Tomcat.
> >
> > On one of my JSP pages, I try to display an image, the path of which is
> > an absolute path (say, C:\somePic.jpg) pointing to a location on the
> > server on which the application is deployed. However when I try to
> > access this web page from a different machine, it looks for this image
> > file on the local machine and not the server. How can I specify an
> > absolute path but still make sure that the jsp page is picking up the
> > image from the server and not the local machine on which it is being
> > run?

>
> Uh-huh.. well, to fix that, simply... wait (checks sub.)
>
> Sub: URGENT! ....
>
> Oh.. (checks watch) apparently I'm too late.
> Never mind.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> [ Look into ServletContext.getRealPath() ]
>
> Andrew T.


 
Reply With Quote
 
Daniel Pitts
Guest
Posts: n/a
 
      11-05-2006

javadev wrote:
> Ok, what happens now when I use application.getRealPath(absPath) where
> absPath is a string that contains the absolute path of the file (say,
> C:\somePic.jsp) is that the absolute path just gets appended to the
> path of the application on the server so it ends up as "C:\Program
> Files\Tomcat\webapps\myApp\C:\somePic.jpg which still does not work.
> Any ideas on what I can do to fix this?


Please don't top post, thanks.

Generally its a bad idea to serve files outside of some predefined
docroot. If you server C:\somePic.jpg, what is to prevent someone from
retrieving anything else on your hard drive? Its best to move the jpg
files into some resource directory under your webapp root.

Good luck,
Daniel.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How does one get an absolute absolute file path? James Byrne Ruby 3 09-14-2010 06:02 PM
How do I convert an absolute path into a relative path Nigel Wilkinson Ruby 2 07-25-2005 07:37 PM
Absolute path in Manifest Class-Path header? bo_kid@yahoo.com Java 10 05-30-2005 01:43 PM
absolute path versus relative path in JSP Matt Java 3 07-08-2004 08:31 PM
Make a relative url path from an absolute path to another one Thomas Guettler Python 3 10-27-2003 04:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57