• 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

How to handle Servlet Exception Correctly

 
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am currently building a sample we site using spring, but I have decided to post it here in Servlet since I think this is still servlet specific question.

Kindly look at my code. It just basically stream files into the response object so that the user can download it.


Now, my question is, how are we going to gracefully handle servlet exception?

Example is, I click the link to the file but the file isn't in the resources folder, my browser will just go blank as if nothing has happened.

But when I viewed my Tomcat logs, I saw that there is a Stream Closed Exception. I would like to know, how can I notify the user that there was an error
in downloading the file so that they are well informed instead of a blank browser screen.

I am not sure if this is possible...Thanks.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

mark reyes wrote:Now, my question is, how are we going to gracefully handle servlet exception?


Not by eating the exception as you are doing here.

If you want to handle exceptions in a global fashion, use the error page capability of the deployment descriptor. You should always set this up so that any unhanded exceptions have somewhere to go to handled in a reasonable fashion.

I am not sure if this is possible...


Of course it is. For specific exceptions that you don't want to go to the global handler, redirect to a page that explains the problem when you detect the exception.
 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,

Got your message here! Thanks.
 
This one time, at bandcamp, I had relations with a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic