struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "arunkumar S" <>
Subject Re: Forward a action from one action programmatically in STruts 2.0
Date Fri, 16 Mar 2007 19:57:35 GMT

Thanks for the inputs. my req. will not satisfy your suggestion.

My req. is I have to load different Jsps depending on the user
profile. eg <>. for user with profile = "abc",

i will have JSps like 1_abc.jsp,2_abc.jsp,3_abc.jsp

for user with profile = def , i will have jsps like 1_def.jsp,2_def.jsp etc..

one way of solving this is to mention all the Jsp for users with
different profile in the results and then forward

it in the action itself.


<action name=action1 class = action1>




<action name=action2 class = action2>




return corresponding result in each action based on the users profile.

but the pblm here for each action the application developer has to
define results for each user.

I am thinking of moving this to framework.

Below is the new approach.

<action name=action1 class = action1>



<action name=action2 class = action2>



<action name= "*">



Now , in an action1.class & action2.class depending on the user
profile i construt 1_abc.action or

 1_def.action and 2_abc.action or 2_def.action respectively . and if
i can forward with 1_abc.action the below

definition present in the STruts.xml will take care of forwarding it
to 1_abc.jsp /1_def.jsp  depending on the user automatically.

<action name= "*">



FOr this i need to programmatically forward to an action so that i can
leverage the above mentioned facility.

I hope i have made things clear.Let me know if have any suggestions.



The way I solve this is by returning the value you want and setting up the
action chain on struts.xml file:


   class MyAction 1 .. {

   public String execute(){
             return "foo";
             return "bar";

Then on the Strutus XML file:

  <action name= "MyAction"  class. = ....>
      <result name="foo" type="chain"> FooAction</result>
      <result name="bar" type="chain"> BarAction</result>

 PS. Make sure you use type="chain"!
 Hope this helps.

On 3/15/07, arunkumar S <[EMAIL PROTECTED]> wrote:


I have a requirement where in the action has to be forwarded based on
certain runtime conditions.The destination will be decided only on the
if(Input = "Case1" )
forward action1
forward action2.

Basically i want to acheive a simple forward( requestdispatcher.forward()
) in
ActionClass in Struts 2.0.

How can we acheive this in Struts 2.0. I dont have any API to acheive

Any inputs pls?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message