1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)

Struts Tutorials

Q.How you can do Exception Handling in Struts ?

There are two approaches available for the exception handling in struts.

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"
input="/empform.jsp" >
<exception key="error.system" type="java.lang.RuntimeException" path="/exception.jsp" />


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


Defining the Exceptions Globally for the struts-config.xml : ( If RuntimeException in any Action class , control goes to exception.jsp)
<exception key="error.system" type="java.lang.RuntimeException" path="/exception.jsp" />

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.

Reviews and Comments

PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2019

About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy