aspose file tools*
The moose likes Servlets and the fly likes img src= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "img src="..." has problem when using "forward"." Watch "img src="..." has problem when using "forward"." New topic
Author

img src="..." has problem when using "forward".

Frank Sikuluzu
Ranch Hand

Joined: Dec 16, 2003
Posts: 116
I have a servlet "TestServlet" doing the following:
RequestDispatcher rd;
ServletContext sc = this.getServletContext();
rd = sc.getRequestDispatcher("/test.jsp");
rd.forward(req, res);
in test.jsp it has the following line
<a href="/myapp/servlet/TestServlet?param=a" ><img src="images/pic.gif" alt="" ></a>
The servlet is put in "myapp/WEB-INF/classes/" folder and the jsp is in
"myapp" folder. Then I open a browser and go to "http://localhost ort/myapp/servlet/TestServlet?param=..", what I find is the picture doesn't show up. However, when I open "http://localhost ort/myapp/test.jsp" the picture shows there. So somehow the problem is from "forward". But I don't see anything wrong here. Please help !
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61662
    
  67

The src url for your image tag needs to be server-relative. For example, let's say your web app is loaded at context 'xyz':


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61662
    
  67

It doesn't really have anything to do with the forward, but with the URI that the browser is trying to use as the base reference.
Another option is to use the <base> tag to establish an artificial relative base.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: img src="..." has problem when using "forward".