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
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 ]
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
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.
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