Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

images display problem with dispatcher.forward()

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Matthew the BASE tag worked perfectly fine
[ October 07, 2003: Message edited by: pervaiz gul ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Always! Wait. Never. Shut up. Look at this tiny ad.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic