This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv 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 REST with Spring (video course) this week in the Spring 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.
subject: servlet resource.
jQuery in Action, 3rd edition