0

I'm working on a web project using java/ jsp/ servlets/ html/ css in eclipse tomcat, where everything is in the WebContent folder.

In my jsp files... When I try to include other jsp files (using a link like "/fileName.jsp" in jsp include directive) I can do that successfully. But When I try to include image files (using a link like "/fileName.jpg" in the <img src=""> tag) nothing happens. Nothing happens because instead of looking in the WebContent folder for image file it looks in the tomcat home directory, i.e. Instead of looking at "http ://localhost:port/projectName/..." it looks at "http: //localhost:port/..." Why does it look at the wrong location only with <img src=""> tags but not in <%@ /> tag.

A workaround for this is that I start giving absolute paths "/projectName/..." However doing this means I'm hardcoding project name everywhere. This is what I do not want.

рüффп
  • 5,172
  • 34
  • 67
  • 113
Nikhil
  • 163
  • 2
  • 14

3 Answers3

0

Don't include binary content in an ascii output. Why not just use the img tag? If you need to do something to produce a jpeg, I would use a Servlet.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • Using a servlet to produce a jpeg is unknown to me. Can you elaborate, or post some links? – Nikhil Dec 03 '13 at 05:17
  • Here is a [link](http://www.javaworld.com/javaworld/jw-05-2000/jw-0505-servlets.html) and [here](http://stackoverflow.com/questions/2979758/writing-image-to-servlet-response-with-best-performance) is [another](http://www.codebeach.com/2008/02/creating-images-in-java-servlet.html). – Elliott Frisch Dec 03 '13 at 05:23
0

Because the jsp-Links in the website are getting processed and the image links not. Either change the image path or develop an filter that changes the images'links.

Lukas Eichler
  • 5,689
  • 1
  • 24
  • 43
0

Yes Templar, that could have been a way to solve my problem.

However, I simply changed the Context Root of my project from "Project Name" to "/" in Eclipse. This solved my problem.

Nikhil
  • 163
  • 2
  • 14