How exception handling is provided in struts?

Answers were Sorted based on User's Feedback



How exception handling is provided in struts?..

Answer / sitaram

to handle the errors:

in struts project to handle the error objet by using
ActionError object and to handle the errors by using
ActionErrors object.

for suppose

ActionError ae1=new ActionError("err.one");

ActionError ae2=new ActionError("err.two");

Action Errors aes=new ActionErrors();

aes.add(ae1);

aes.add(ae2);

saveErrors(request,aes);//store the errors object in request
object

to handle exception:

1)using try and cach blocks

2)using declarative exception handling technique

to handle the exceptions by using global exceptons tag in
struts-config.xml

<global-exceptions>

<exception key="gen.err"
type="java.lang.ClassNotFoundException" path="/gen.jsp"/>

whenever that exception will be came it executes the
gen.jsp page.

Is This Answer Correct ?    12 Yes 0 No

How exception handling is provided in struts?..

Answer / 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

More Struts Interview Questions

Can we have multiple struts config files ?

0 Answers  


What are the sections into which a strut configuration file can be divided?

0 Answers  


What is the use of form bean in struts?

0 Answers  


How many types of action clases are there in stuts and their uses?

15 Answers   OHO, TCS, Wipro,


what is struts? why Struts?

6 Answers   CTS, Infosys, TCS,






What do you mean by dynaactionform?

0 Answers  


What steps are required to for an application migration from Struts1 to Struts2?

0 Answers  


What is apache struts used for?

0 Answers  


What is the use of ActionErrors in Struts

1 Answers  


Lists the bundled validators in struts?

0 Answers  


Give an alternative way to protect jsp’s with not much features from direct access.

0 Answers  


Give the details of xml files used in validator framework?

0 Answers  


Categories