• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cannot get images to show in JSP file.

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, all. I've searched all over the web and see this is a common problem... However, the suggestions I've come across have yet to solve my problem.

I have a simple JSP file and I'm attempting to display an image. My folder structure in Eclipse is:

MMABully
--- WebContent
------META-INF
------WEB-INF
------index.jsp
------Success.jsp
------Logo.jpg


Code in my index.jsp file:



You'll notice an img src tag and below it an a href tag. Going to Success.jsp works, but Logo.jpg will not display.

I've also tried <%= response.getContext() %> in the image tag but that doesn't work either.

So both Success.jsp and Logo.jpg reside in the same place. I can get to one but not the other. I'm totally stumped.

Other things I've tried:

- Putting Logo.jpg in the webapps/ folder in my Tomcat directory

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

K.C. Brawley wrote:I've also tried <%= response.getContext() %> in the image tag but that doesn't work either



Why would it? There's no such method.

The correct way to reference the context path is with the EL expression ${pageContext.request.contextPath}. You should not hard-code into the URL paths.

Because you are running this from the IDE, I've moved this to the IDEs forum as it's likely a setup issue rather than a real problem.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. I recommend against running from an IDE. They're great as a smart editor, but suck, in my opinion, as a run-time environment for web apps.
 
K.C. Brawley
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

K.C. Brawley wrote:I've also tried <%= response.getContext() %> in the image tag but that doesn't work either



Why would it? There's no such method.

The correct way to reference the context path is with the EL expression ${pageContext.request.contextPath}. You should not hard-code into the URL paths.

Because you are running this from the IDE, I've moved this to the IDEs forum as it's likely a setup issue rather than a real problem.



Hi, Bear. I appreciate the response. My apologies for the error. I meant <%= request.getContextPath() %> found here: https://coderanch.com/how-to/java/ResourceUrlProblems

Whether I use the above method or ${pageContext.request.contextPath} the result is the same. Also, this error occurs outside of the IDE as well.

Here are some screen shots that I hope help. This is driving me crazy.

http://i43.tinypic.com/2reqn9h.jpg

http://i39.tinypic.com/ffalb6.jpg

http://i41.tinypic.com/5fp18y.jpg

http://i43.tinypic.com/u8nte.jpg

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the screen shots, the images don't look like they have file types. Or is that Windows just being stupid?

If the image files are correctly named, and if they are in the context root, and if the web app is properly deployed, then the images URL should simply be /context-path/image-name.png (or whatever).

Have you tried displaying them by typing their URL into the address bar?
 
K.C. Brawley
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:In the screen shots, the images don't look like they have file types. Or is that Windows just being stupid?

If the image files are correctly named, and if they are in the context root, and if the web app is properly deployed, then the images URL should simply be /context-path/image-name.png (or whatever).

Have you tried displaying them by typing their URL into the address bar?



The image file is correctly named. That much I am sure. The logo is in the same location as the JSP file and as far as I know the web app is properly deployed. I start Tomcat in Eclipse and then look at the page from Firefox.

I did in fact try getting to the image via the address bar and received a 404 error. I also moved an HTML file into the folder and received a 404 error.

I am very new to servlets and JSP. Do I need to do something in a servlet to get the image to display? Currently I'm using just one servlet (in a form) that does a simple user name/password lookup. Here it is:



Again, I'm new when it comes to this stuff. I'm working my way through Head First: Servlets and JSP currently. All I know is that both index.jsp and Success.jsp can be viewed and happens to be referenced in the servlet and those are the only things that can be viewed.
 
K.C. Brawley
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More information:

I installed Tomcat 7 from Eclipse (version Indigo). Eclipse allowed me to choose the version of Tomcat I wanted and then made me choose a folder location which was on my Desktop.

Does anyone have any ideas?
 
K.C. Brawley
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is resolved. I needed to post my files in workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\MMABully and believe it or not nowhere told me to do this. I just sort of found this folder by accident.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I cannot believe that that is the supported way to deploy in eclipse; but as I said, I don't use an IDE as a run-time platform so I avoid all the silliness.
 
reply
    Bookmark Topic Watch Topic
  • New Topic