I have tried the following
According to my documnentation (JSP the Complete reference by Phil Hanna)
code should equal 404 if the url does not exist. Even if it does exist I always get back 401.
What am I missing? Is there an easier way to does this.
Any help much appreciated,
Originally posted by Shaun Appleton:
[QB]I want to check to see if an image exists on a webserver. If it does then I will display it if it does not the I will display a default.
Shaun: You can use the JSTL to do this very easily with code simliar to:
Author ofJSTL: Practical Guide for JSP Programmers
Check out the Javadoc on UrlConnection.
Another thought: if the image is on the same server on which your code is running, it might be a tad more efficient to just check the file system (servletContext.getRealPath() will help you out there) rather than going through another network connection.