命名空间/操作名称没有映射的Action。 - [未知位置]

时间:2016-07-29 10:58:00

标签: jsp tomcat struts2

我正在实现一个小的struts 2 Web应用程序,而我得到上述异常我是struts 2的新手。我已经从堆栈流量和其他网站上看到了一些建议。我尝试了所有的建议仍然无法解决我的问题。

这里是我的strust.xml,并保存在WEB-INF / clasess旁边。

<struts>
<constant name="struts.devMode" value="true" />
    <package name="default" namespace="/" extends="struts-default">
         <action name="Login">
            <result>pages/login.jsp</result>
        </action> 

        <action name="Welcome" class="com.tcs.action.DemoAction">
            <result name="SUCCESS">pages/welcome.jsp</result>
        </action>
    </package>

</struts>

这是我的行动课。

package com.tcs.action;

public class DemoAction {


    private String userName;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String execute(){

        return  "SUCCESS";
    }

}

我在webapp / pages文件夹中保留了login.jsp和welcome.jsp 这是我的login.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head></head>
<body>
    <h1>Struts 2 Hello World Example</h1>

    <s:form action="Welcome">
        <s:textfield name="userName" label="Username" />
        <s:submit />
    </s:form>

</body>
</html>

和welcome.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head></head>
<body>
    <h1>Struts 2 Hello World Example</h1>

    <h2>
        Hello
        <s:property value="userName" />
    </h2>

</body>
</html>

我希望我添加了所有与struts相关的jar,因为我没有找到任何类没有找到或没有类def发现异常。 我希望我在很多地方问过已经存在的问题,但我仍然没有解决问题。

1 个答案:

答案 0 :(得分:0)

这很有趣,但我必须说我做错了http://localhost:8089/StrutsApp 这是我的网址,我忘记添加http://localhost:8089/StrutsApp/Login.action 那就是它。现在工作正常。

相关问题