5

I have a JSP page in which there is a hyperlink to add a user.

<html:link action="openadduser.do"> Add New User < /html:link>

My struts-config file contains

<action-mappings>
        <action path="/login" name="LoginForm" validate="true" input="/index.jsp"
            type="useraction.LoginAction">
            <forward name="successadmin" path="/home.jsp" />
            <forward name="failure" path="/index.jsp" />
            <forward name="successuser" path="/welcome.jsp" />
        </action>

    <action path="/adduser" name="AdduserForm" validate="true" input="/adduser.jsp"
            type="useraction.AdduserActions">
            <forward name="success" path="/userconfirm.jsp" />
        </action>

       <action path="/openadduser" name="AdduserForm" validate="true" type="useraction.AdduserAction"
            input="/adduser.jsp">
            <forward name="success" path="/userconfirm.jsp" />
        </action>
</action-mappings>

And my adduser.jsp contains code

<html:form action="/adduser">
     < h1 align="center">  ADD NEW USER < /h1>
     < bean:message key="label.fname"/> <br/>
     <html:text property="fname"></html:text><br/>
     <html:errors property="fname" /><br/>
     </html:select>
    <html:submit/>
</html:form></body></html>

AdduserAction.java contains

public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception 
    {
        AdduserForm adduserForm = (AdduserForm) form;

        fname = adduserForm.getFname().toString();
        System.out.println(fname);
        return mapping.findForward("success");

    }

I am using a Tomcat server. After I click on the submit button to add a user, it gives the following error. HTTP Status 500 - No action instance for path /adduser could be created in struts.

I think there is a problem in the struts-config file. What can I do to remove this error? Thank you for the help.

martieva
  • 131
  • 2
  • 11
vikiiii
  • 9,246
  • 9
  • 49
  • 68

3 Answers3

3

You cannot extend the 'Action' class in your LoginAction. That's the only reason for no action instance for path. You must extend the Action class, don't forget...

OnaBai
  • 40,767
  • 6
  • 96
  • 125
3

I think appending .do in your jsp should solve the problem

<html:form action="adduser.do">
Zohaib
  • 7,026
  • 3
  • 26
  • 35
  • @vicky try removing the "/" from jsp, that is try action="adduser.do" – Zohaib Dec 20 '11 at 04:32
  • It is still giving same error. Actually in struts-config file i have a separate action for submit button on add user and separate action for the hyperlink to open add user jsp . Is there is some conflict in this? – vikiiii Dec 20 '11 at 04:36
  • SEVERE: No action instance for path /adduser could be created java.lang.ClassCastException: useraction.AdduserActions cannot be cast to org.apache.struts.action.Action – vikiiii Dec 20 '11 at 04:38
  • The action class is not in the classpath or you must have miss spelt the action class!!! – Pradeep Dec 20 '11 at 04:44
  • Pardeep is right, this might be the reason. By the way is it AdduserAction or AdduserActions because you are using oth, or are they really different classes. – Zohaib Dec 20 '11 at 04:47
  • They are different classes. But content is same. Actually i was just trying if it could work. But it is not working.Both have same content. – vikiiii Dec 20 '11 at 04:48
  • I have added AdduserAction class in my question. – vikiiii Dec 20 '11 at 04:51
  • does AdduserAction extends Action class? – Zohaib Dec 20 '11 at 04:53
  • Yes,It is extending Action class. – vikiiii Dec 20 '11 at 04:57
  • @Zohaib actually when you asked whether AdduserAction extends Action class? Then only i extend it. But it again was showing error. But when i put "/" in adduser.jsp for "/adduser.do" . It started working. Thank you so much. – vikiiii Dec 20 '11 at 05:00
  • Why is this the accepted answer when it's followed by a discussion about it not working? – Jobbo Dec 06 '18 at 09:25
0

@vicky : in action tag change validate="true" to validate="false"

It worked for me...

Baz
  • 36,440
  • 11
  • 68
  • 94
Adil Khan
  • 21
  • 5