【问题标题】:There is no Action mapped for namespace [/] and action name [] associated with context path [/struts]没有为命名空间 [/] 和动作名称 [] 映射的动作与上下文路径 [/struts] 关联
【发布时间】:2013-07-23 15:44:47
【问题描述】:

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

消息:

    Stacktraces
    There is no Action mapped for namespace [/] and action name [] associated with context path [/struts]. - [unknown location] 
        com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
        org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
        org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
        com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58
    ..................

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="default" namespace="/*" extends="struts-default">
            <action name="login"
                class="training.struts.action.LoginAction">
                <result>login.jsp</result>
            </action>
        </package>
        </struts>

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"
        version="2.5">

        <display-name>Struts Lab</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>

        <!-- Spring Config -->
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                    /WEB-INF/springServlet/appServlet/mvc-servlet.xml,
                    /WEB-INF/db/db-cfg.xml,
                    /WEB-INF/springServlet/application-security.xml
            </param-value>
        </context-param>

        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>

        <servlet>
            <servlet-name>mvc</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/springServlet/appServlet/mvc-servlet.xml</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>

        <servlet-mapping>
            <servlet-name>mvc</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>

        <!-- Spring Security -->
        <filter>
            <filter-name>springSecurityFilterChain</filter-name>
            <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        </filter>

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

        <!-- *** -->
        <welcome-file-list>
            <welcome-file>login.jsp</welcome-file>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>

        </web-app>

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

src/main/java
----+training.struts.action.LoginAction.java
src/main/webapp
----+WEB-INF
--------+classes
-----------+struts.xml
--------+db
-----------+db-cfg.xml
--------+springServlet
-----------+appServlet
---------------+mvc-servlet.xml
-----------+application-security.xml
--------+index.jsp
--------+login.jsp
--------+web.xml

更新: 傻了好难过=( 我已将 login.jsp 从 WEB-INF 移至 webapp root 并解决了问题。

更新 2: 我做了一些调查: 如果我从 web.xml 中删除“welcome-file-list”块,容器将在 webapp 根目录中查找“index.jsp”,以显示为应用程序运行的第一个视图。如果我删除“index.jsp”,那么我会得到相同的异常消息: 没有为命名空间 [/] 和动作名称 [] 映射的动作与上下文路径 [/struts] 关联

所以在我看来,如果您在错误消息中有空的操作名称以及正确的 struts xml 设置,那么第一步应该是启动 JSP 可用性检查。

干杯,伙计们。

【问题讨论】:

  • namespace="/*" 在包和带有 Struts2 的 spring mvc 中。你从哪里复制那个糟糕的代码/conf...
  • @Alexandr T 我完全是新手,我自己写的...我在 Srping 上有我的小应用程序,我需要在其中集成 Struts 来学习 struts..
  • @Alexandr M 你的意思是Spring MVC对Struts2自己的mvc或smthg的干扰吗?我应该这样调查吗?
  • Servlet 应该映射到它自己的上下文。
  • @Roman C Roman 可以详细描述您的评论吗?对不起,但我无法得到它=(

标签: eclipse spring jsp struts2 action-mapping


【解决方案1】:

将以下空白操作添加到"/" 包命名空间中的 struts.xml 文件中,当您仅尝试访问您的 url(如 appid.app.com)并且它不会显示时,它将显示 index.html错误。通常它会添加一个空白动作,应用引擎会将空白动作重定向到您的欢迎文件。

    <action name="" class="com.candi.actions.Dashboard" method="noAction">
        <result name="success">index.jsp</result>
    </action>

【讨论】:

    【解决方案2】:

    在你的命名空间中添加 / 而不是 /* :

    <package name="default" namespace="/" extends="struts-default">
    

    或者如果问题没有解决,您可以使用Config Browser Plugin

    配置浏览器插件是一个简单的工具,可帮助在运行时查看应用程序的配置。在调试可能与配置问题有关的问题时,它非常有用。

    【讨论】:

      【解决方案3】:

      好的,所以我将 login.jsp 放在了我的 web-app 文件夹结构中的错误位置。 那是错误

      【讨论】:

        【解决方案4】:

        在struts.xml中添加如下包

        <package name="default" namespace="/" extends="struts-default">    
             <action name="login"
                    class="training.struts.action.LoginAction">
                    <result>login.jsp</result>
            </action>   
        </package>
        

        【讨论】:

        • 附加要调用操作的 JSP 页面
        • 我不手动调用任何操作 - 我只是在 eclipse 中的服务器上运行项目
        • 阅读&lt;action name="*"987654323@后,我的大脑中突然死掉了2337个神经元
        • @AndreaLigios: &lt;action name="*" 是可用于捕获不匹配引用的操作的通配符默认值。
        • @AleksandrM 我知道,I've used it too,但是对于未找到的操作 URL 的默认回退;在这个答案中,它似乎被用来避免声明任何动作......无论 URL 是什么,它总是会回退到 LoginAction :|
        【解决方案5】:

        我将包标签中的命名空间更改为'/',问题解决了!!!

        【讨论】:

          【解决方案6】:

          对我来说,我将 web.xml 文件的开始标记从

          <web-app>
          

          <web-app id="WebApp_ID" version="2.4"
                   xmlns="http://java.sun.com/xml/ns/j2ee"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
                   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
          

          【讨论】:

            猜你喜欢
            • 2016-05-17
            • 2016-07-06
            • 1970-01-01
            • 2016-05-30
            • 1970-01-01
            • 1970-01-01
            • 2015-04-29
            • 2014-01-10
            • 1970-01-01
            相关资源
            最近更新 更多