【问题标题】:Struts 2 GAE No action mapped for namespace [/]Struts 2 GAE 没有为命名空间映射操作 [/]
【发布时间】:2013-02-01 06:29:16
【问题描述】:

我正在为项目需求学习 Struts 2,但遇到了一些问题。

按照本教程在:

http://www.mkyong.com/google-app-engine/google-app-engine-struts-2-example/

以及我所做的额外工作:

  • 将 index.jsp 添加到 war 文件夹中
  • 将 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">
        <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>
    
        <listener>
            <listener-class>com.mkyong.listener.Struts2ListenerOnGAE</listener-class>
        </listener>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>
    

现在,当我重建和加载时

    http://localhost:8888

而不是看到我应该在我的 index.jsp 中包含的内容,我得到了一个

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

有人能指出我正确的方向吗?我在 SO 中看到了一些其他类似的问题,但他们的解决方案不适用于 Struts 2 + GAE 的这个特定示例。

我的 struts.xml

    <struts>
        <package name="user" namespace="/User" extends="struts-default">
            <action name="Login">
                <result>pages/login.jsp</result>
            </action>
            <action name="Welcome" class="com.mkyong.user.action.WelcomeUserAction">
                <result name="SUCCESS">pages/welcome_user.jsp</result>
            </action>
        </package>
    </struts>

文件夹结构

我不能发布图片所以,http://i.imgur.com/KSPmaMr.png

用于下载的库完全相同

http://www[dot]mediafire[dot]com/?utliwvcmo63o8l7

【问题讨论】:

  • 我猜,你没有在你的 struts.xml 文件中映射动作名称,请给我你的 struts.xml 文件。
  • @arvin_codeHunk 嗨,根据教程,不需要将 struts 映射到 index.html 吗?抱歉,这是新手。
  • 我猜你已经从 web.xml 文件中删除了所有内容,上面是 web.xml 中的唯一内容,因为我看不到实际查找 struts.xml 文件的 filterdispatcher 的映射.
  • 好的,您的 struts.xml 文件是否在您的根目录中,我的意思是您放置 struts.xml 文件的位置?
  • 我知道,index.jsp 不需要 action_mapping,但是如果您复制粘贴了代码,那么您需要映射驻留在视图中的所有操作

标签: google-app-engine indexing struts2 namespaces action-mapping


【解决方案1】:

好的,我有你的问题,

把你的 struts.xml 改成这个

  <struts>
       <package name="default" extends="struts-default" namespace="/">
            <action name="Login">
                <result>pages/login.jsp</result>
            </action>
            <action name="Welcome" class="com.mkyong.user.action.WelcomeUserAction">
                <result name="SUCCESS">pages/welcome_user.jsp</result>
            </action>
        </package>
    </struts>

我想这会起作用,因为如果您将 struts.xml 文件放在根目录中,filterDispatcher 会在根文件夹中搜索 struts.xml 文件。

【讨论】:

  • 我已经更改了它,但它不起作用。据我所知,您将包名称从用户更改为默认值?我试图在欢迎文件工作中指向 index.jsp。 struts.xml 在我的根 /src 文件夹中
  • 好的,你的网址localhost:8888,为什么这里只显示你的端口名,应该是这样的localhost:8888/your-project-name
  • 是的,我可以毫无问题地加载xxxx.com/index.jsp。但是我试图在输入xxxx.com 时加载 index.jsp,在这种情况下是 localhost:8888 我不希望我的用户去xxxx.com/projectname 我觉得当他们只能去 xxxx 时这太过分了。 com
  • 你刚刚错过了重点,如果你使用 ide 在 localhost 上运行你的项目,那么应该是这样的 localhost:8888/your-project-name
  • 对不起,我错过了。但是,项目名称是 Struts2GoogleAppEngine。加载时,localhost:8888/Struts2GoogleAppEngine 也会出现同样的错误。
【解决方案2】:

@Eleazar 我关注了您在问题中提到的 mykong 教程链接。就我看到该教程而言,没有使用index.html&lt;welcome-list&gt; 文件在应用程序启动时未提及任何操作时使用。

在该教程的 step:8 中,他们提供了运行测试所需的 urlhttp://localhost:8888/User/Login.action。它与欢迎列表中的文件无关......

更新:

您收到该错误是因为您已将 struts2 过滤器添加为 /*,并且您的操作命名空间用于 /User/ 没有操作命名空间。添加带有名称=“默认”和名称空间=“/”的包,即&lt;package name="default" extends="struts-default" namespace="/"&gt;&lt;/package&gt; 将解决您的问题。它将命中&lt;welcome-file&gt;

【讨论】:

  • 是的,我知道您来自哪里。但是,我想包含一个 index.jsp 作为我尝试部署的任何地方的“登陆”页面。在这种情况下,它是 localhost:8888 我想要 localhost:8888,或者当我在网站上部署时,首先让它们的根指向我的 index.jsp。这是我想要实现的,但它不允许我这样做。
  • ok 然后在 struts.xml 中定义另一个包,即 &lt;package name="default" extends="struts-default" namespace="/"&gt;&lt;/package&gt; 在你的包之前命名为用户。不要在里面写任何动作。将 index.jsp 保存在 web-content 文件夹中。并运行应用程序。希望你能看到你的 index.jsp 页面
  • 感谢您的回复,我也刚刚尝试过,但仍然出现错误。 ):
  • Eleazar 您是否完全按照文章进行操作?你有文章所有库的相同版本吗?如果您致电localhost:8888/User/Login.action,则不可能再收到“/”命名空间的错误,您将位于 /User 命名空间...
  • @AndreaLigios 是的,安德里亚,你是对的。但这不是问题。我可以达到 Login.action 就好了。问题是我试图在localhost:8888 之类的主域中访问 index.jsp,而默认值为 index.html 我使用了与教程中所述的库完全相同的版本。我将附上第一篇文章中使用的所有库的 zip。是的,我密切关注所有步骤。如果你尝试一下,我相信你会遇到同样的错误。我在 Eclipse IDE juno 上。
猜你喜欢
  • 1970-01-01
  • 2016-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-25
  • 2019-10-16
相关资源
最近更新 更多