Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

URGENT! Please help! Access files through absolute path

Thread view: 
javadev - 05 Nov 2006 15:28 GMT
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
Andrew Thompson - 05 Nov 2006 15:53 GMT
...
> I have a java based web application deployed on Apache Tomcat.
>
[quoted text clipped - 6 lines]
> 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.
javadev - 05 Nov 2006 17:23 GMT
Thanks Andrew

How can I get a handle to the servletcontext object?

Swetha

> ...
> > I have a java based web application deployed on Apache Tomcat.
[quoted text clipped - 20 lines]
>
> Andrew T.
javadev - 05 Nov 2006 17:25 GMT
I figured I can use application.getRealPath coz application is of type
ServletContext.

Thanks
Swetha

> ...
> > I have a java based web application deployed on Apache Tomcat.
[quoted text clipped - 20 lines]
>
> Andrew T.
javadev - 05 Nov 2006 17:52 GMT
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?

> ...
> > I have a java based web application deployed on Apache Tomcat.
[quoted text clipped - 20 lines]
>
> Andrew T.
Daniel Pitts - 05 Nov 2006 22:40 GMT
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.