|
|
|
| HOME | J2ME | Struts | AJAX | SOAP | SOA | MEDIA STREAMING | AXIS | | |
|
|
Struts for Beginners: Exception HandlingBack | Tutorial Home | Next Like all other configurable features in Struts, Exceptions can be also handled using configurations. This configuration methodology is usually called declarative exception handling. Normal exception handling we do is programmatic exception handling. Struts configuration file can be configured to catch exception. Not a single line is needed in your code needs to be changed to handle these exceptions. Shut down your database and execute the login page. When you submit the login details, the browser overflows with exception messages. If you properly analyze these error messages, you will find that the root cause is java.sql.SQLException. Now let us handle this exception the STRUTS WAY. Create a JSP page dbServerDown.jsp with error message. This is page to be displayed when the exception occurs. <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"
%> Add the exception handling declarations in the Struts configuration file <action path="/loginAction" Finally create the error message referred to as key in the above declaration. This error message should be configured in MessageResources.properties db.exception=Internal Error, Please Try after some time....................
Run the login program in the browser. Do a proper login once and then shut down your database. Execute the login page again. When you submit the login details you will be shown the error message you have configured in the MessageResources.properties. If we properly analyze the code above we havent done any changes
in the Action class, all we have done is do configurations in the configuration
files. Back | Tutorial Home | Next site comments powered by Disqus |
|
| toolbar powered by Conduit |
|
| Copyright © 2009. All rights reserved | Terms and Conditions | About | Contact | Feed Back | |