我正在为一个项目要求学习 Struts 2,但我遇到了一些问题。
按照本教程在:
http://www.mkyong.com/google-app-engine/google-app-engine-struts-2-example/
我做了额外的事情:
<?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>
<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>
我想这会奏效,因为 filterDispatcher 搜索 struts.xml 如果将 struts.xml 文件放在根目录中,则文件在根文件夹中。
关于google-app-engine - Struts 2 GAE 没有为命名空间映射的操作 [/],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14640938/