Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validating an image before display using c:import

 
Sridhar Bandari
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to display an image(available on the server as a resource) in the webpage using jstl. In the code, I have the image url, but before displaying it in the page, I need to validate if the image is available on the server to display.

I tried to use <c:import> but not able to verify if the image exists there. Following is the code I used.

<c:import url="${logoUrl}" var="imageData" />
<c:if test = "${imageData!=null && not empty imageData}">
display image..${imageData}
</c:if>

When the image is not available on the server, it still enters the if condition but gives a message as "the requested resource is not available"

Please let me know where I am going wrong.

Thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, first of all, what are you planning to do with the image data once you fetch it?

Secondly, the comparison !=null and not empty are redundant. Use one or the other.

Finally, read the JSTL Specification for <c:import>. It's acting exactly as the specification dictates.

But again, using <c:import> with images doesn't make a whole lot of sense in the first place.
 
Sridhar Bandari
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the response. Image data is of no use for me. The whole idea of the code is to check if the image exists before rendering the <img> tag in the page. Please suggest if it is not the appropriate way.

To be more clear, the original code will be

<c:import url="${logoUrl}" var="imageData" />
<c:if test = "${imageData!=null && not empty imageData}">
<img src="${logoUrl}"/>
</c:if>


-thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read the JSTL Specification as I recommended?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic