Question

Is there anyway to check if required resource available or not

My code

<img id="photo" src="http://localhost:8081/test.png" />

Now suppose my image name is test.png

now what i want to do is check if http://localhost:8081/test.png available or not

e.g <c:if test="${resource}">

if not available i want to put default.png as http://localhost:8081/default.png in the src which is available that i know for sure.

and If it is available then i will put src value to http://localhost:8081/test.png

How to do this??

No correct solution

OTHER TIPS

You can use following code from this answer. Please note this is not JSTL based solution as stated in question.

function imageExists(image_url){

    var http = new XMLHttpRequest();

    http.open('HEAD', image_url, false);
    http.send();

    return http.status != 404;

}

I think you should develop your own custom tag, that returns one picture or another depending on the availavility of the first.

You should use two parameters: One for the image that may be available or not, and another for the "default" image.

Here's a good introduction to the subject.

http://www.tutorialspoint.com/jsp/jsp_custom_tags.htm

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top