How exception handling is provided in struts?
Answer Posted / qim2010
There are two approaches available for the exception
handling in struts.
Declarative:
Exceptions are defined in the struts-config.xml file and if
the exception occurs the control is automatically passed to
the appropriate error page. The <exception> tag is used to
define the exception in the struts-config.xml file.For
Example : (( If RuntimeException in SaveEmpAaction class ,
control goes to exception.jsp)
<action path="/saveEmp"
type="com.techfaq.SaveEmpAaction"
input="/empform.jsp" >
<exception key="error.system"
type="java.lang.RuntimeException" path="/exception.jsp" />
</action>
Where
Key: The key defines the key present in
MessageResources.properties file to describe the exception
occurred.
Type: The class of the exception occurred.
Path: The page where the control is to be followed in case
exception occurred.
Handler: The exception handler which will be called before
passing the control to the file specified in path attribute
OR
Defining the Exceptions Globally for the struts-config.xml :
( If RuntimeException in any Action class , control goes to
exception.jsp)
<global-exceptions>
<exception key="error.system"
type="java.lang.RuntimeException" path="/exception.jsp" />
</global-exceptions>
Programmatic:
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.
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
What are the steps of struts installation?
In which method of action class the business logic is executed?
What is difference between actionform and dynaactionform?
When do I need “struts.jar” on my classpath?
What are the advantages of spring mvc over struts mvc?
When should we use SwtichAction?
Explain about struts?
Why aren’t the struts tags maintained as part of the jakarta taglibs project ?
What are the classes used in struts?
What is struts2 namespace?
How many struts config file in a struts application?
What is the purpose of execute() method?
What is xml based validation in struts2?
What are the steps involved in creating a strut application?
What is the purpose of '@customvalidator'?