• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp include problem

 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • 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
 
Billybob Marshall
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
danny liu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!