This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

images display problem with dispatcher.forward()

 
Gul Khan
Ranch Hand
Posts: 173
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am trying to forward request from a servlet to a jsp page which has some images on it whose path is relative to context. When i forward through servlet the images are not displayed coz error in the path. the path is changed to
my-app/servlet/images/1.gif rather than my-app/images/1.gif
I can give the image path in files as ../images/1.gif but than if i use response.sendRedirect rather than dispatcher forward, it will give an error!
what path should i give to my images so they are displayed both via forward and sendRedirect the same way.
Thanks and Regards
Gul
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the <HEAD> section of the document you may add a <BASE> tag with the href attribute set to the base location of your base. You may then access the path to your image from that base.
Check out the HTML specs for more info.
[ October 07, 2003: Message edited by: Matthew Phillips ]
 
vijaykumar shah
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
very simple...... ..
use ../image/1.gif or what ever
u see u are done
vijay
 
vijaykumar shah
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the error is because of something else.. check if you have any System.out.println ();
or anything u add in the response after redirecting or creating response object
if yes remove that and check the code it will work
 
Gul Khan
Ranch Hand
Posts: 173
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is no system.out line in the servlet. sorry it does not show an error rather it wont show the image. if i use ../images/1.gif it will be OK when i forward to it but i need to use the page via sendRedirect also and in that case the image will not work again.
 
Gul Khan
Ranch Hand
Posts: 173
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Matthew the BASE tag worked perfectly fine
[ October 07, 2003: Message edited by: pervaiz gul ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13044
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason you got that error is that for all resources such as CSS or images that have relative URLs, the browser tries to request the resource by building a URL based on where the page came from - that is, your servlet's address. Not surprisingly that creates a URL that the server can't serve.
The BASE tag tells the browser what to build a url from instead of your servlet address.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic