NotesArt
NotesArt

Reputation: 383

run action on success of a action

I am trying to run another action on the success of first action but what i get is error saying requested resource is not available. Check the below code from struts.xml file.

<action name="login" class="org.shobhan.action.LoginAction" >
<result name="success" type="dispatcher">/showProfile</result>
<result name="error" type="redirect">/Login.jsp</result>
</action> 
<action name="showProfile" class="org.shobhan.action.ShowProfileAction" >
<result name="success">/profile.jsp</result>
</action>

i have both java files LoginAction and ShowProfileAction are present in same folder.

Upvotes: 1

Views: 359

Answers (3)

Dave Newton
Dave Newton

Reputation: 160271

To redirect to an action, use the actionRedirect result type.

<result type="redirectAction">showProfile</result>

Upvotes: 4

Quaternion
Quaternion

Reputation: 10458

<result name="success" type="dispatcher">/WEB-INF/showProfile.jsp</result>    
<result name="error" type="dispatcher">/WEB-INF/Login.jsp</result>

The above does NOT call another action, but will work if you have those JSPs in WEB-INF.

Dispatcher resolves to a jsp (well in this case) and redirect starts the call from scratch. Is /Login.jsp callable from the url? In other words is CONTEXT_ROOT/Login.jsp accessible? If so then you can forward to it, if not then it is not possible.

In general it is not a good idea to redirect after an error because it will remove field errors (and any other variables and messages which might be useful).

If you want to call an action see: Action redirect in struts.xml for more options about calling actions and some advice.

PS: dispatcher is the default type, and success is the default name so you can simply write...

<result>/WEB-INF/showProfile.jsp</result>    
<result name="error">/WEB-INF/Login.jsp</result>

Upvotes: 1

RJ Cuthbertson
RJ Cuthbertson

Reputation: 1528

shouldn't your success call have a file extension?

Upvotes: 0

Related Questions