J2EE is not a file server architecture. The only way to get the names of image resources is if the web application was designed with an application function to look into whatever places your images are being held and enumerate what it finds there.
This task is further complicated because the official format for a webapp is a WAR file, and unless the server is working with an "exploded" (unzipped) copy of that WAR, there are no actual files, just indexed members of the WAR (ZIP entries). Or, in other words, there's nothing to run the java.io.File list method against.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.