URGENT! Please help! Access files through absolute path

J

javadev

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
 
A

Andrew Thompson

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.
 
J

javadev

Thanks Andrew

How can I get a handle to the servletcontext object?

Swetha

Andrew said:
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.
 
J

javadev

I figured I can use application.getRealPath coz application is of type
ServletContext.

Thanks
Swetha


Andrew said:
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.
 
J

javadev

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 said:
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.
 
D

Daniel Pitts

javadev said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top