File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Forward in an action forms reset method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Forward in an action forms reset method." Watch "Forward in an action forms reset method." New topic

Forward in an action forms reset method.

Patrick McDonogh
Ranch Hand

Joined: Oct 13, 2005
Posts: 89
Hi all,

I am having a spot of bother trying to redirect a request to a specified forward if an exception is thrown in the action forms reset method.

To illustrate i have the following action defined in struts-config.xml.
<action path="/myAction" type=""
name="theForm" scope="request" validate="true"
<forward name="caughtException" path="/"/>
<forward name="success" path="/"/>

As you can see i have a caughtException forward specified in the action. This is the path i want to forward to if an exception is thrown in the "theForm"'s reset method.
i.e. The forms reset method is shown below.

public void reset(ActionMapping mapping, HttpServletRequest request) {
AnObject o = new AnObject()
try {
catch (IntegrationException ie) {
ActionForward forward = mapping.findForward("caughtException");
// I now want to forward to this action.

Does anyone know to forward to the forward which i retrieve in the catch block, that corresponds to this line in the struts-config file? <forward name="caughtException" path="/"/>

Thankyou for your help with the matter and i hope you all have a great day and weekend.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Sorry, Patrcick, you can't do it this way because there's no way to return a forward from an ActionForm.

My suggestion would be to move this logic out of the reset method and into an action class that uses this ActionForm. Then you can forward to another action or JSP if an exception is thrown.

Consultant, Sima Solutions
Ravish Ahuja

Joined: Nov 29, 2004
Posts: 13
You could possibly use RequestDispatcher to forward the request.
I agree. Here's the link:
subject: Forward in an action forms reset method.
It's not a secret anymore!