aspose file tools*
The moose likes Servlets and the fly likes images display problem with dispatcher.forward() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "images display problem with dispatcher.forward()" Watch "images display problem with dispatcher.forward()" New topic
Author

images display problem with dispatcher.forward()

Gul Khan
Ranch Hand

Joined: Sep 03, 2003
Posts: 173
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

Joined: Mar 09, 2001
Posts: 2676
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 ]

Matthew Phillips
vijaykumar shah
Greenhorn

Joined: Jul 02, 2003
Posts: 23
very simple...... ..
use ../image/1.gif or what ever
u see u are done
vijay
vijaykumar shah
Greenhorn

Joined: Jul 02, 2003
Posts: 23
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

Joined: Sep 03, 2003
Posts: 173
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

Joined: Sep 03, 2003
Posts: 173
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

Joined: Mar 22, 2000
Posts: 12823
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: images display problem with dispatcher.forward()