【问题标题】:There is no Action mapped for namespace [/] and action name [duplicate]没有为命名空间 [/] 和操作名称映射的操作 [重复]
【发布时间】:2016-06-25 20:41:28
【问题描述】:

我正在学习一个 Struts2。我有struts.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

    <package name="default" namespace = "/" extends="struts-default" >
        <action name="loginStudent" class = "org.dream.action.LoginAction">
            <result name="login">/login.jsp</result>
            <result name="success">/index.jsp</result>
            <result name="input">/login.jsp</result>
        </action>
    </package>



</struts>

我有我的LoginAction.class

package org.dream.action;

import org.apache.commons.lang3.StringUtils;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction implements Action {

    private String studentId;
    private String password;

    public String execute(){
        if(getStudentId().equals("test")||getPassword().equals("test")){
            return SUCCESS;
        }else return LOGIN;
    }


    public String getStudentId() {
        return studentId;
    }

    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

}

我有 jsp 文件。

Login.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
 <%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Page</title>
</head>
<body>
    <s:form action="loginStudent">
        <s:textfield key="studentId" label="Student Id"/>
        <s:textfield key="password" label="Password"/>
        <s:submit/>
    </s:form> 

</body>
</html>

当我按下 sumbit 按钮时出现错误:

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [loginStudent] associated with context path [/Struts2Demo]

我找不到这个错误的原因,请帮助我!!

【问题讨论】:

    标签: java eclipse jsp configuration struts2


    【解决方案1】:

    指定&lt;s:form&gt; 标记的命名空间属性,该属性应与您的struts.xml 配置文件中的命名空间属性匹配。

    <body>
        <s:form action="loginStudent" namespace="/">
            <s:textfield key="studentId" label="Student Id"/>
            <s:textfield key="password" label="Password"/>
            <s:submit/>
        </s:form> 
    
    </body>
    

    【讨论】:

    • 检查更新的答案。不要忘记重启你的容器/服务器。
    • 又没有任何改变
    • 我什么都不懂。我重新启动了eclipse,程序没有出错。我开始我的初始代码,没有更改
    • 您几乎总是需要在更改配置后重新启动您的 tomcat/应用程序服务器。
    • @Yuriy Eclipse 可能有错误但没关系,问题是当您运行应用程序时,它缺少struts.xml 中可用的配置设置。如果您将其部署在本地 Eclipse 存储文件中的元数据文件夹中,您应该检查该文件夹是否包含所有必需的文件。因为你是新来的,所以你应该阅读how to accept/upvote answers
    猜你喜欢
    • 2016-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-02
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    相关资源
    最近更新 更多