Wednesday, 20 June 2012

Global Exception Mappings:

We have seen how we can handle action specific exception. We can set an exception globally which will apply to all the actions. For example, to catch the same NullPointerException exceptions, we could add <global-exception-mappings...> tag inside <package...> tag and its <result...> tag should be added inside the <action...> tag in struts.xml file as follows:
<?xml version="1.0" encoding="UTF-8"?>
   "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
<constant name="struts.devMode" value="true" />
   <package name="helloworld" extends="struts-default">

         <exception-mapping exception="java.lang.NullPointerException"
         result="error" />

      <action name="hello" 
         <result name="success">/HelloWorld.jsp</result>
         <result name="error">/Error.jsp</result>


No comments:

Post a Comment