struts2 - 没有为与上下文路径 [/projectName] 关联的命名空间 [/] 和操作名称 [actionName] 映射的操作。

标签 struts2 action-mapping

我正在使用注释开发 struts 2.0,并创建了一个 Web 项目,在该项目中我只是进行登录并在成功登录后重定向到另一个 jsp。但是,每当我尝试登录时,它都会显示一条错误消息:- 没有映射与上下文路径 [/strutsDemo2] 关联的命名空间 [/] 和操作名称 [welcome] 的操作。

我已将以下 jar 文件添加到我的项目中:

asm-3.3.jar asm-all-2.2.3.jar cglib-nodep-2.2.3.jar commons-fileupload-1.3.jar commons-io-2.0.1.jar commons-lang3-3.1.jar freemarker-2.3.19.jar javassist-3.11.0.GA.jar ognl-3.0.6.jar struts2-convention-plugin-2.3.15.1.jar struts2-core-2.3.15.1.jar xwork-core-2.3.15.1.jar

我的jsp是:

   <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%>
 <%@taglib uri="/struts-tags" prefix="s" %>
<!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>Demo</title>
</head>
<body>
<s:form action="welcome" validate="true">
    <s:textfield name="userName" label="userName"></s:textfield>

    <s:submit value="submit"></s:submit>
</s:form>
</body>
</html>

我的 Action 类是:

         import org.apache.struts2.convention.annotation.Action;
         import org.apache.struts2.convention.annotation.Namespace;
    import org.apache.struts2.convention.annotation.Result;
    import org.apache.struts2.convention.annotation.ResultPath;
    import org.apache.struts2.convention.annotation.Results;

    import com.opensymphony.xwork2.ActionSupport;
    import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
    import com.opensymphony.xwork2.validator.annotations.ValidatorType;

@Namespace("/")
@ResultPath("/")

@Results({
       @Result(name="success", location="/Welcome.jsp"),
       @Result(name="input", location="/index.jsp")
    })
public class Welcome extends ActionSupport{

    private String userName;
    private String message;

    @RequiredStringValidator(type=ValidatorType.FIELD, message="Name is Required")
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }

    @Action(value="welcome")
    public String execute()
    {
        return SUCCESS;
    }



}

Web.xml:

     <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>strutsDemo2</display-name>
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
    <init-param>
         <param-name>struts.devMode</param-name>
         <param-value>true</param-value>
      </init-param>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

最佳答案

请更改您的<s:form action="welcome" validate="true"><s:form action="Welcome" validate="true">

在标签的操作属性中使用“Welcome”而不是“welcome”。 “W”大写

关于struts2 - 没有为与上下文路径 [/projectName] 关联的命名空间 [/] 和操作名称 [actionName] 映射的操作。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18785107/

相关文章:

java - 没有为与上下文路径关联的命名空间 [/user] 和操作名称 [user!add] 映射的操作

java - 使用 struts2 为命名空间错误映射的操作

struts2 - Struts Hello world 示例 : There is no Action mapped for namespace [/] and action name error

java - 带有 Struts Filter 和 Tomcat 的 Spring Boot

java - 严重: Exception occurred during processing request: null java. lang.NullPointerException

json - 带注解的 Struts2 JSON 插件

struts2 - Struts 2 中的 validate() 和 reset() 方法有哪些示例?

java - 支柱 2 : There is no Action mapped for namespace [/]

java - Struts 2 带点的动态 URL 模式

java - Struts2 portlet 正在执行 Liferay 刷新的默认操作(而不是其当前操作)