
How you can do Exception Handling in Struts ?

Hi friends,
In sruts you can handle the exception in two ways.
1 : Declarative Exception Handling: You can defined in struts-config.xml file. Ands if the exception occurs then controls will automatically passed to the appropriate errorpage.
Where Key : The key defines the key present in MessageResource.properties file to describe the exception. 2 : Programmatic Exception Handling: key="database.error.duplicate"
path="/UserExists.jsp"
type="mybank.account.DuplicateUserException"/>
Type : The class of the exception occurred.
path : The page where the controls is to be followed is case excepation eccured.
Handler : The exception handler which will be called before passing the controlto the specified in patt attributes.
In this approach the exceptions are caught using normal java language try/catch block and instead of showing the exception some meaningful messages are displayed.
In this approach the flow of control is also maintained by the programs.
The main drawback of the approach is the developer has to write the code for the flow of the application.

Hi friends,
In sruts you can handle the exception in to three ways
1 : Declarative Exception Handling:
You can defined in struts-config.xml file. Ands if the exception occurs then controls will automatically passed to the appropriate errorpage.
<exception
key="database.error.duplicate"
path="/UserExists.jsp"
type="mybank.account.DuplicateUserException"/>
Where
Key : The key defines the key present in MessageResource.properties file to describe the exception.
Type : The class of the exception occurred.
path : The page where the controls is to be followed is case excepation eccured.
Handler : The exception handler which will be called before passing the controlto the specified in patt attributes.
2 : Programmatic Exception Handling:
In this approach the exceptions are caught using normal java language try/catch block and instead of showing the exception some meaningful messages are displayed.
In this approach the flow of control is also maintained by the programs.
The main drawback of the approach is the developer has to write the code for the flow of the application.
Thanks.

I think addFieldError(fiedName,Error Message);
is the right and well user friendly way to handle the exception. Just right addFieldError() in catch{ } and return "input"; from there .
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.