| Author |
validating an image before display using c:import
|
Sridhar Bandari
Greenhorn
Joined: Feb 03, 2012
Posts: 2
|
|
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
Joined: Jan 10, 2002
Posts: 56224
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Sridhar Bandari
Greenhorn
Joined: Feb 03, 2012
Posts: 2
|
|
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
Joined: Jan 10, 2002
Posts: 56224
|
|
|
Did you read the JSTL Specification as I recommended?
|
 |
 |
|
|
subject: validating an image before display using c:import
|
|
|