• 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown

Spring MVC Webapp on OpneShift - how can I display .jpg image from JSP?

Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to deploy a Webapp in Java using Spring MVC on OpenShift cloud server (using JBoss & MySQL cartridges). While I am able push my code and retrieve data from MySQL database, I am unable to access/display images in my JSP pages.

Images are stored in MyProject/resources/images/ folder (MyProject/resources/images/stockmarket.jpg)

My controller-servlet.xml file looks like this:

In my JSP, this is how I try to access the image file:

However, in my webpage the image does not show-up. Can anyone please help? Where am I making a mistake? Rest of the functionality in my Webapp is working fine.
Posts: 1845
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What URL do you use to access your web application?
What is the URL that the broken image is using to look up the image? (You can find out using the Browser F12 developer tools, or just viewing source on the generated page)
What URL should it be using?  Can you fiddle around with the URL manually to load the image successfully?

Couple of things I think might be contributing here:
You say your image is at:  MyProject/resources/images/stockmarket.jpg
But then you try and reference it with:  /resources/stockmarket.jpg

What happened to "MyProject" ?
What happened to "/images" ?

The image is using an absolute URI - it starts with "/", so will look for the picture from the root of the webserver.
Most probably your URL needs to include the servlet context value

However most probably, the correct url to be looking is at "/MyProject/resources
The context root for a web application is dynamic (normally based on the name of the war file)
The standard way of doing this is to
- Include an expression in the image url to the servlet context into the URL
- use a JSP/JSTL tag to convert a url for you (looks slightly tidier)


Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic