This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes servlet resource. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet resource." Watch "servlet resource." New topic

servlet resource.

shiva rao
Ranch Hand

Joined: May 26, 2005
Posts: 31
Hi All,

I am try to check whether a image is there with in the war file or not. If found I will display the image at front end. If not I want to show a custom message.

Right not I am checking like
try {
return "images/client1.gif";
}catch (Exception e){
return "Not Found";
In the above code if it throws an exception then I get the "Not Found" message.

Is there a better way to achieve this.

Bala Krishna
Ranch Hand

Joined: Jan 26, 2001
Posts: 95
You could get the RealPath of the image using the getRealPath method in ServletContext class. That path can be used to construct a object and you can call the exists() method on that File object, to see if the image exists. There may be better and simpler ways of doing this.
I agree. Here's the link:
subject: servlet resource.
Similar Threads
<p:graphic image> in conjuction with <p:fileupload>
Part II upload file size
Display Image Problem
Handling Browser refresh
Problem in displaying an image