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

有帮助吗?

解决方案

Your config file is in the wrong place.

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top