ist_lion
ist_lion

Reputation: 3209

No action found for specified url

New to struts & trying to go through a basic tutorial and am getting the error InvalidPathException: No action config found for the specified url

My url that's blowing up is: http://localhost:8080/UserAction.do?method=add

Here is part of my struts-config.xml

<struts-config>
    <form-beans>
        <form-bean name="UserForm" type="Form.UserForm" />
    </form-beans>
    <action-mappings>
        <action path="/user" type="Action.UserAction"  input="/pages/user.jsp"  parameter="method"  name="UserForm" scope="session">
   <forward name="success" path="pages/user.jsp">
    </action-mappings>
</struts-config>

My UserAction.Java

public class UserAction extends DispatchAction {

   public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

    //Do some stuff
    UserForm userForm = (UserForm)form;
    userForm.setMessage("Added user");
    return mapping.findForward("success");
}

}

Here is the UserForm

public class UserForm extends ActionForm {

   private String message;

   public UserForm() {
       super(); 
   }

   public String getMessage() { return this.message; }

   public void setMessage(String inMessage) { this.message = inMessage; }

}

Finally my user.jsp

<html>
....
<html:form action="user">
   <table>  
     <tr> 
       <td>
         <html:submit value="add"  onClick="submitForm()"  />
       </td> </tr></table></html:form>
</html>

submitForm is simple

function submitForm(){
   document.forms[0].action = "UserAction.do?method=add"
   document.forms[0].submit();

Upvotes: 1

Views: 10575

Answers (1)

JB Nizet
JB Nizet

Reputation: 692231

You configured a single action, mapped to the path /user. So the URL to invoke this action is http://host:port/contextPathOfTheWebApp/user.do. In your case, since it seems you deployed the app as the root application, it should be http://localhost:8080/user.do.

I don't see the point in submitting the form with JavaScript. Especially if the only thing it does is changing the correct path to an incorrect one. BTW, if the form is submitted by just pressing enter in one of its inputs, the JavaScript code will be bypassed.

You should also prefer request-scoped form beans, and respect the Java naming conventions (packages in lower-case)

Upvotes: 2

Related Questions