File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes how to load an image without using context root Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how to load an image without using context root" Watch "how to load an image without using context root" New topic

how to load an image without using context root

shwetank singh

Joined: Apr 02, 2007
Posts: 26

This may sound absurd, yet i can use some thoughts here!
i've a jsp which has link to an image http://<server_ip>/context-root/largeImages/Collection/a.jpg
this will search and load an image a.jpg which should be under the context-root

what i wish to understand is,
a) is it possible, without changing this line of code, to somehow refer the image without context-root, if the image is not on same machine which has the servlet container?
b) if doing this is not possible without changing code, what changes should be brought about so that the image could be loaded provided hosting configuration stated above.

~ access the image as /largeImages/Collection/a.jsp and not /context-root/large...

please help!
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63854

If the image is remote, you need to provide the entire URL.

If all remote resources are coming from the same place, you can shorten the URL by using the <base> HTML tag, but that affects all URLs so you can only use it if you want it to apply to all images, style sheets, links and script files.

Are you just looking for a shorthand for the pages?

[Asking smart questions] [About Bear] [Books by Bear]
shwetank singh

Joined: Apr 02, 2007
Posts: 26
Hi Bear
Thanks for reply!
here is a background on where this question comes from:
i have an ear (having dynamic and static content) which has some jsp's that refer to images in below stated fashion (absolute path).
i have, to leverage upon powers of app server, moved the static content to a web-server and serve it from there.
this is done using plugins and directives used on alias in httpd.conf tells the webserver...if a resource request comes with /context-root/... , it will be served by app server, or else the webserver can handle that (we can conveniently overlook this lest this becomes a question for server forums )

now to the problem..we already have so many jsp's having absolute path (url's to images/css etc.) that making a change everywhere is..what to say : )
and hence the question: can i refer to a static resource without using context-root?
>the image is remote.
>yes all resources will come from webserver and we can put them up into any structure in document-root.
>no this essentially is not a shorthand. i am trying to figure out a way to lookup a resource without actually referring to the context-root

please suggest further.
I agree. Here's the link:
subject: how to load an image without using context root
It's not a secret anymore!