aspose file tools
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 Head First Android 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.
It is sorta covered in the JavaRanch Style Guide.
subject: servlet resource.
It's not a secret anymore!