• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp include problem

 
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a directory (main) in which I have a page genericPage.jsp. Also, I have subdirectories (sub) in main directory that I want to include in genericPage.jsp using page directive. The problem is that when I include html file from sub in main my images do not show up. In sub I have images coded as so when I include sub page in main, page is looking for images in main (since it's coded like that) and not in sub, if I code image as [code]<img src="../sub/img.gif"> and include it in main, I am not in main directory anymore. Absolute URL does not seem to work in jsp:include. What's the solution?
thanks,
Alex
 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
links such as <img> are relative to the client's perspective, not necessarily to the referencing page's perspective. It looks like you are perhaps using inclusions in an ill-conceived way.
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess the only solution is to code images with absolute URL. Does not work in all cases for me though, since sub dir will sometimes be first in main2 and then in main. When it's moved to main, main2 is deleted.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, when image (and other resource references) are resolved by the browser, it uses the URL of the request (not where a file was loaded from) as the base.
So your images either need to use a server-relative URL, or your page can establish a new base via the <base> tag.
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you should put all images in one folder, e.g., webapps\application1\images
Every time you wanna use an image, just insert the following line:
<img src="/images/xxx.jpg">
In that way, the corresponding image can always be accessed.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see how using a single folder makes any difference. Once you've resigned yourself to using server-relative HREF's or the base tag, it's moot how you organize the images.
 
danny liu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using one folder to hold all images really make a big difference. It is easier to maintain.
For image upgrade, I just replace the images in the /images with the new ones. I don't need to go through each sub folder and replace these images
one by one.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If that's easier for you, that's fine. For a complex web application with potentially hundreds of images, it's usually easier to keep them organized in a hierarchy.
My point was, that the choice of how to store the images (single folder or otherwise) is completely moot with regards to the issue of the topic.
reply
    Bookmark Topic Watch Topic
  • New Topic