Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception Handler for doGet or doPost  RSS feed

 
Mishaal Khan
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Curious about Exception handler for doPost and doGet methods i.e

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

}

If I call this doGet method using a link in html or jsp and any exception occurs inside
doGet, it will be handled by HttpServlet super class or Container?

thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will not be handled by default and will be propagated out until the error appears in the response sent to the browser.

You should declare an error handler in the deployment descriptor to handle the error as appropriate to your application.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
You should declare an error handler in the deployment descriptor to handle the error as appropriate to your application.


Hi Bear, i feel, using the try and catch is better than this kind of approach . the deployment descriptor is used for common error handling right?

please correct me
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you pollute each and every servlet with a try/catch block when you can declare it once in the deployment descriptor?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, Bear suppose you are using a DAO class method [say updateEmployee() which is throws a UserFriendly Exception ] in servlet ,then you need to handle in try catch right ?

Please Correct me,if i am wrong
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method ( updateEmployee() )will have the try/catch code, most likely. Even if it doesn't have one, error pages come handy. After all, you are not supposed to handle SQLException that was thrown by code written by someone else .

Hope this helps .
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit Ghorpade wrote:you are not supposed to handle SQLException that was thrown by code written by someone else


Here, i am not talking about the SQLException , A userfriendly exception(logic error)

please clarify the scenario
 
Khirod Patra
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, This a sample Example to Handel the error through Deployment Descriptor(web.xml)

<!-- Reporting an error using a JSP page -->

<error-page>

<exception-type>The Exception Class</exception-type>

<location>/error.jsp</location>

</error-page>

Khirod..


 
Khirod Patra
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A user friendly exception(logic error)----->To handle these error,you need to assign the the respective error message(user define or any predefine ) to request object and call to the error page using a condition.

Khirod..


 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all .
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From try and catch only , you will be propagated to the exceptions defined in the web.XML page
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!