I need to determine if an image exists in a JSP tag so I can display a default if it doesn’t exist. What is the best way to access the War root so that I can check to see if the image exists? Or is there a better solution?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
ServletContextmethod getResource can be used for features like this. If the resource (the image) doesn’t exist, this method returnsnull. In that case, a default image can be displayed.Note that the URL this method returns is not the URL to use as the ‘src’ attribute in an
<img>tag. It is most likely afile:orjar:protocol URL that wouldn’t make sense on another host. In this application, its only tested to see if it isnull, and not actually by the JSP.