Monday, April 4, 2011

Quick Recap: Chapters 25 to 29

Let us now quickly recap what we learnt in the previous few chapters on Servlet Exception Handling…

Introduction to Servlet Exception Handling:

• Exception Handling is a powerful feature of the J2EE Technology and we can use it to handle unexpected behavior in our code
• There are categories of error codes that give us a fair idea of what went wrong. For ex: error codes 5XX signifies that something was wrong on the server side

The sendError Method:

• You can use the sendError method of the HttpResponse to send error messages to the browser
• It takes two parameters – the error code and a error message
• You can override the default behavior of the method and have custom code to handle exceptional cases
• The sendError method will set the appropriate headers and content body for an error message to return to the client.
• Using this method will commit the response (if not already committed) and terminate it. The data stacked in the output stream to the client before calling sendError() method is ignored

The setStatus Method:

• The setStatus method sets the status code for a given response
• Use this method, instead of sendError, when there is no exception or serious error
• If there is a serious error, the sendError method should be used; otherwise use setStatus.

The WebApp Log:

• Log files get written with the sequence of events handled by the Servlet
• You can write custom content into the log file in order to help us handle exceptional situations better

Key Terms we learnt in this section are:

• exception
• sendError()
• setStatus()
• Logging
• Status codes
• Error codes

Previous Chapter: Chapter 29 - WebApp Log

Next Chapter: Self Test - Chapters 25 to 29

No comments:

Post a Comment

© 2013 by All rights reserved. No part of this blog or its contents may be reproduced or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior written permission of the Author.