• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

servlet resource.

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 {
session.getServletContext().getResourceAsStream("images/client1.gif").read();
return "images/client1.gif";
}catch (Exception e){
e.printStackTrace();
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.

Thanks!
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could get the RealPath of the image using the getRealPath method in ServletContext class. That path can be used to construct a java.io.File 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic