• 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

handling servlet exception gracefully

 
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have put a code in my servlet to handle the exception gracefully. Basically when the exception is thrown, the error.jsp should be displayed.
My servlet code has
below code.


The doService method calls one more method which throws exception.
The web.xml has below tags.

<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>

but When the exception is thrown instead of seeing the error.jsp , I am seeing the IE error page for error 500.

What am I doing wrong?

thanks
Trupti
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no doService method.

You are implementing your servlet the wrong way. use doPost, doGet, etc.
 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sebastian Janisch wrote:There is no doService method.

You are implementing your servlet the wrong way. use doPost, doGet, etc.



Yes, ther is no method like doService().

But if you want to override service method then simply use


However, this does make the Servlet less portable, since it is now dependent on preprocessed request data.

Since the routing takes place in service(), you generally do not override service() in an HTTP Servlet. Instead, override doGet() and/or doPost(), etc., depending on the type of request you expect.
 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Trupti,
This probably due to an IE bug/peculiar behaviour. If the message body size is less than a certain amount of byte (I believe 513 bytes) IE will try to be intelligent and show its own message.

The obvious work around is explained here.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess trupti means the method(doService) calls inside service method, trupti override the service method right?..anyway the way you are handling the exception is OK . but if you are catch and throw the particular type of exception would be even better.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your browser under internet options, make sure "show Friendly HTTP Error messages" is not checked. That may be overriding the display of your error message.
 
trupti nigam
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nishan Patel wrote:

Sebastian Janisch wrote:There is no doService method.

You are implementing your servlet the wrong way. use doPost, doGet, etc.



Yes, ther is no method like doService().

But if you want to override service method then simply use


However, this does make the Servlet less portable, since it is now dependent on preprocessed request data.

Since the routing takes place in service(), you generally do not override service() in an HTTP Servlet. Instead, override doGet() and/or doPost(), etc., depending on the type of request you expect.



Sorry for not mentioning other facts. My servlet extends the org.springframework.web.servlet.FrameworkServlet. Hence there is doService method and not the service.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you really throwing an exception report to the user and not logging it?

How in the world do you expect to be able to debug your application?

It seems to me that a minimum treatment is:

1. log the stack trace
2. IF the exception shows that the app is now unusable, throw an UnavailableException so the container wont try another request
ELSE create and throw a ServletException with the message that will be some use to the client - such as try again later.

Bill
reply
    Bookmark Topic Watch Topic
  • New Topic