Search code examples
struts2chainingaction-mapping

action chaining error:There is no Action mapped for namespace [/] and action name [login.action] associated with context path [/chaining]


my task is on struts2 action chaining,my program name is chaining ,i am using correct syntax,but it is not working.

struts.xml

<action name="register" class="RegisterAction"> 
    <result name="success" type="chain">login.action</result>    
</action>
<action name="login" class="LoginAction" >
    <result name="success">/login.jsp</result>  
</action>

RegisterAction.java

public class RegisterAction {

    public String execute() {
        return "success";             
    }
}

LoginAction.java

public class LoginAction {

    public String execute() {
        return "success";
    }
}

but when i run program,it gives the following error occurs

There is no Action mapped for namespace [/] and action name [login.action] associated with context path [/chaining].


Solution

  • Remove the suffix from your chained Action name, from this

    <result name="success" type="chain">login.action</result>  
    

    to this

    <result name="success" type="chain">login</result>  
    

    Note that Action Chaining is not recommended, Redirect Action or some other ways should be preferred.

    From the official documentation:

    Don't Try This at Home
    As a rule, Action Chaining is not recommended. First explore other options, such as the Redirect After Post technique.

    Take a look at this answer too: https://stackoverflow.com/a/4761955/1654265