You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Gudla, Madhuri" <MG...@americanaships.com> on 2002/10/24 05:31:41 UTC
NEED HELP with Customised Struts Exception Handling
I have an Action class( see BookAction below ), which calls
'SchedulingDelegate.updateRotation()' inside the 'try' block.
The call to 'updateRotation()' throws a 'TestProcessException'.
MY OBJECTIVE IS: I want this 'TestProcessException' to be handled by the
struts framework and automatically call
my 'MyExceptionHandler' class to handle this
exception.
MY PROBLEM IS: How do i make the struts framework call the
'MyExceptionHandler' to handle the 'TestProcessException'?
How do i code my Action class to make this
happen?
This is what i have in my struts-config.xml:
<action-mappings>
<action path="/createBook"
name="bookForm"
type="BookAction"
input="/CreateBook.jsp"
scope="request"
validate="true">
<exception
handler="com.foo.framework.strutscustomization.MyExceptionHandler"
type="com.foo.framework.exception.TestProcessException"/>
</action>
</action-mappings>
public class BookAction extends Action {
public ActionForward perform(ActionMapping mapping,
ActionForm form, HttpServletRequest req,
HttpServletResponse res)
{
System.out.println("Start perform(" + form + ") . . ." );
//String title = req.getParameter("title");
Book book = new Book();
//BookForm bookform = (BookForm) form;
//book = bookform.getBook();
DynaValidatorForm dynaform = (DynaValidatorForm) form;
String title = (String) dynaform.get("title");
book.setTitle(title);
System.out.println("After creation of book: " + book.getTitle()
);
////////////////////Testing Exception Handling
try
{
System.out.println("~~~~~~~~~~Calling scheduling delegate");
SchedulingDelegate sd = new SchedulingDelegate();
SchedulingDelegate.updateRotation();
}
catch(TestProcessException tce){
System.out.println("tce occurred");
// throw new TestProcessException("ActionClass :",tce);
}
//////////////////////
req.setAttribute("BOOK", book);
return mapping.findForward("bookCreated");
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>