【发布时间】:2012-11-21 02:13:08
【问题描述】:
我们在 com.example.common.action 下有一个名为 'Index' 的 Action 类,并带有 @ParentPackage('default') 注释,它在 struts.xml 的 package 指令中声明,其命名空间为“/”,并且扩展“struts-default”。它还声明了@Result,以便响应与其execute() 方法返回的字符串值相对应的jsp 文件。
在我们的 struts.xml 中,配置了以下 struts 设置以及约定插件所需的其他必要配置。
<constant name="struts.action.extension" value=","/>
当访问 /my_context/none_existing_path 时,请求显然会命中这个 Index 类,并返回 Index 的 @Result 部分中声明的 jsp 的内容。 但是,如果我们提供 /my_context/,我们会收到以下错误:
HTTP 状态 404 - 没有为与上下文路径 [/my_context] 关联的命名空间 [/] 和操作名称 [] 映射的操作。
我们想知道为什么访问/my_context/none_existing_path,其中none_existing_path没有匹配的动作,可以回退到Index类,但是当请求的URL只是/my_context/时返回错误。
目前,我们的约定插件设置声明如下:
<constant name="struts.convention.package.locators.basePackage" value="com.example"/>
<constant name="struts.convention.package.locators" value="action"/>
奇怪的是,如果我们将 struts.convention.package.locators.basePackage 的值更改为 om.example.common,其中上述Index文件可以通过缩小搜索范围立即找到,请求/my_context/显示在Index类的@Result部分声明的jsps的内容。但是,由于我们的操作类分布在 com.example.[a-z].action 包中,其中 [a-z] 表示我们在包结构中拥有的大量目录,因此我们不能使用这个技巧作为解决方法。我们还尝试将 index.jsp 放置在类路径的顶层,并将 index.jsp 重定向到 /my_context/index,这确实有效,但不是我们想要的。这可能是一个错误吗?
感谢您的回复。 提前谢谢你。
【问题讨论】:
标签: struts2 action-mapping struts2-namespace