This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Frank Sikuluzu
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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':
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!