【问题标题】:There is no Action mapped for namespace [/] and action name [] associated with context path [duplicate]没有为与上下文路径关联的命名空间 [/] 和操作名称 [] 映射的操作 [重复]
【发布时间】:2014-10-02 04:31:09
【问题描述】:

我在 stackoverflow 上查看了所有类似的 Q,但没有帮助,抱歉。我与他们的主要区别是我在错误消息中得到了 EMPTY 操作名称。谷歌搜索没有帮助:(希望有人能提示在哪里寻找问题的根源。thx

Error:

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

--------------------------------------------------------------------------------

type Status report

message There is no Action mapped for namespace [/] and action name [] associated with context path [/LoginApplication].

description The requested resource (There is no Action mapped for namespace [/] and action name [] associated with context path [/LoginApplication].) is not available.

WARNING: Could not find action or result: /LoginApplication/
There is no Action mapped for namespace [/] and action name [] associated with context path [/LoginApplication]. - [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

web.xml

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>Struts 2 Web Application</display-name>

<filter>
<filter-name>struts2</filter-name>
<filter-
class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-
class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

</web-app>

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>
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.devMode" value="true" />

<constant name="struts.custom.i18n.resources" value="ApplicationResources" />

<package name="user" namespace="/" extends="struts-default">
<!-- http://localhost:8080/Struts-Example/User/Login.action -->
<action name="login">
<result>/Pages/HomePage.jsp</result>
</action>

<action name="validatelogin" class="/LoginApplication/src/ValidateLogin"
method="execute">
<result name="Success">/Pages/Success.jsp</result>
<result name="Failure">/Pages/Failure.jsp</result>

</action>
</package>
</struts>

页面: 主页.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>
<title>Validate Login</title>
</head>
<body>
<s:form action="login" method="execute">
<s:textfield name="username" key="Username" size="20" />
<s:password name="password" key="Password" size="20" />
<s:submit />
</s:form>
</body>
</html>

成功.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>

<head>
<title>Login Application - Authorized</title>
</head>

<body>
Congratulations, <s:property value="username" />!
Welcome to Struts 2 world.
</body>
</html>

Failure.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>

<head>
<title> Login Application - Unauthorized</title>
</head>

<body>
Sorry, You have entered an invalid Username / Password
</body>
</html>

ValidateLogin.java

public class ValidateLogin 
{
public String username;
public String password;

public String getUsername() 
{
    return username;
}

public void setUsername(String username) 
{
    this.username = username;
}

public String getPassword() 
{
    return password;
}

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

public String execute() 
{
    if (this.username.equals("pinkesh") &&    
this.password.equals("pinkesh"))//((this.username.equals("pinkesh")) &   
(this.password.equals("pinkesh")))
        return "Success";
    else
        return "Failure";
}
}

well..image 是不可能的,所以项目结构是:

src/
----ValidateLogin.Java
WenCOntent
-----+User
--------+Pages
------------+HomePage.jsp
------------+Success.jsp
------------+Failure.jsp
-----+web.xml
-----+struts.xml

【问题讨论】:

  • 错误正是消息所说的:您正在尝试访问/,显然,例如,没有操作名称。那里没有配置任何操作,您的所有操作都有名称,例如 /login/validateLogin。此外,JSP 页面应位于WEB-INF 下,以避免直接客户端访问。请考虑更好的压痕卫生。
  • 非常感谢戴夫。您能否建议我应该在 struts.xml 中进行哪些更改以纠正此问题。我尝试将 JSP 页面放在 WEB-INF 下,但仍然出现相同的错误。
  • 你在用eclipse吗?
  • 你输入了什么网址,好像http://localhost:8080/Struts-Example

标签: struts2 struts2-namespace action-mapping


【解决方案1】:

我也遇到了类似的错误。 解决方法是“struts.xml”文件位于“web”文件夹中。

它必须在“src”源文件夹中。

进行更改并重新启动服务器。

【讨论】:

    【解决方案2】:

    默认情况下,程序会找到index.jsp
    如果您的 [/] 目录中没有 index.jsp,则会发生该错误。
    或者你必须在web.xml中选择另一个文件

    解决方案
    在您的web.xml 下添加此代码filter-mapping

    <welcome-file-list>
            <welcome-file>/Pages/HomePage.jsp</welcome-file>
    </welcome-file-list>
    

    【讨论】:

      【解决方案3】:

      谢谢大家。我更改了我的 struts.xml,如下更正了提到的错误和命名约定,并且能够解决问题。

      <?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE struts PUBLIC
      "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
      "http://struts.apache.org/dtds/struts-2.0.dtd">
      
      <struts>
      <constant name="struts.devMode" value="true" />
      
      <package name="user" namespace="/User" extends="struts-default">
          <action name="login">
              <result>pages/HomePage.jsp</result>
          </action>
      
          <action name="ValidateLogin" class="com.user.struts.ValidateLogin" method="execute">
              <result name="SUCCESS">pages/Success.jsp</result>
              <result name="FAILURE">pages/Failure.jsp</result>
          </action>
      
      </package>  
      </struts>
      

      【讨论】:

        【解决方案4】:

        我不知道是否还有人遇到这个问题,但这就是我所做的-

        在“helloaction.java”类中更改你的包名

        包括我在内的大多数人都只是写一个教程是如何显示的,所以经过数小时的调试,我终于找到了问题。

        package com.tutorialspoint.struts2;
        

        我已经在我的 action(.java) 类中编写了上述行。在 src 文件夹中创建了一个包“com.tutorialspoint”。但语法实际上意味着 com 包内有一个包 tutorialspoint。所以教程基本上是

        src->com->tutorialspoint->helloaction.java
        

        因此,在所有搜索中都没有找到解决方案后,我在 .java 类和 struts.xml 中都将包的名称更改为“practice”,并且效果很好。

        src->practice->helloaction.java
        

        希望如果有人像我一样犯同样的错误......它会有所帮助。它可能不是解决方案,但当其他一切都没有时,它对我有用。

        【讨论】:

          【解决方案5】:

          修改struts.xml文件,&lt;package name="default" namespace="/" extends="struts-default"&gt;在包中添加namespace="/"属性

          【讨论】:

            【解决方案6】:

            先学习如何在struts.xml中指定一个类

            class="/LoginApplication/src/ValidateLogin" 指定方式错误

            <action name="validatelogin" class="/LoginApplication/src/ValidateLogin" <- this is wrong 
              method="execute">
                 <result name="Success">/Pages/Success.jsp</result>
                 <result name="Failure">/Pages/Failure.jsp</result>
            </action>
            

            如果文件名是ValidateLogin.java,你应该更正它并写class="ValidateLogin"

            如果java类文件在某个包中,那么它应该是

            class="yourPackageName.ValidateLogin"
            

            【讨论】:

              【解决方案7】:

              我也遇到了同样的错误。 通过将struts.xml位置重定位到eclipse项目中src文件夹的根目录解决了这个问题

              【讨论】:

                【解决方案8】:

                struts.xml 文件必须在:“WebContent/WEB-INF/classes/”文件夹中。

                【讨论】:

                  猜你喜欢
                  • 2016-05-30
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2016-07-06
                  • 1970-01-01
                  • 1970-01-01
                  相关资源
                  最近更新 更多