File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes validating an image before display using c:import Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "validating an image before display using c:import" Watch "validating an image before display using c:import" New topic
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: 61654
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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: 61654
    
  67

Did you read the JSTL Specification as I recommended?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validating an image before display using c:import