문제

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??

올바른 솔루션이 없습니다

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top