wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 60822
    
  65

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: 60822
    
  65

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: img src="..." has problem when using "forward".
 
Similar Threads
config.getInitParameter
how to set the module path.
Http Error 500
passing initial parameters to jsp
using modules with JSPs behind web-inf