Action redirect in struts.xml

后端 未结 1 654
星月不相逢
星月不相逢 2020-12-03 11:48

Can I redirect to another action from within a struts actions ? So the result of an action is another action i.e - here is a snippet of struts.xml

    

        
1条回答
  •  春和景丽
    2020-12-03 12:08

    Yes. You can redirect and you can chain. Redirect starts from scratch, it is like you called the other action for the first time while chain keeps the values on the value stack and adds the variables of the new action.

    To forward:

    
        /formsearch.action
    
    

    To chain:

    
        formsearch
    
    

    As a convenience the redirect result type can be changed to a "redirectAction" result type... which lets us write:

     
        formsearch
    
    

    This last one is probably what you want.

    Now a warning, chaining/action redirection is up there with the "goto" statement. Not evil but easy to abuse, you should probably look to moving the deciding logic (the logic that determines what action to call of several to an interceptor) or if the logic is mostly setup related then some type of utility class that is invoked by the actions prepare method (or into the prepare method outright)... If the action needs parameters before prepare is called then use the paramsPrepareParamsStack.

    0 讨论(0)
提交回复
热议问题