1

I am developing a simple HelloWorld struts application. I am doing the configuration using struts.xml file. the welcome page is displayed but when I click on the form submit button, it gives 404 error.

Kindly provide some pointers.

action class:

package client;

public class Hello {

    public String name;
    public String message;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMessage() {
        return message;
    }

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

    public String execute() {
        message = "Hello " + name;
        return "success";
    }
}

namecollect.jsp

<s:form action="hello" method="post">
<s:textfield name="name">Enter name</s:textfield>
<s:submit></s:submit>
</s:form>

struts.xml

<package name="default" namespace="/" extends="struts-default"> 
    <action name="hello" class="client.Hello">
    <result name="success">hello.jsp</result>
</action>
</package>  

This is the package structure:

enter image description here

Tiny
  • 27,221
  • 105
  • 339
  • 599

1 Answers1

1

Your config file is in the wrong place.

By default struts.xml is expected to be at the root of your classpath.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • It is working fine after I copy the struts.xml in the claspath although in namecollect.jsp, I have to define action as hello.action to run the code.Is there anything else that i am missing to run it with just hello and not hello.action? – Divyang Agrawal Jan 02 '14 at 17:58