struts.convention.result.path在Struts2中不工作 [英] struts.convention.result.path is not working in Struts2
问题描述
我目前的项目结构如下
WebContent
WEB-INF
View
TestPage.jsp
other JSP pages...
我的任务是将所有JSP页面内的文件夹WEB-INF和做项目的所有相对变化。
My assignment is to put all JSP pages inside folder WEB-INF and do all relative changes in the project.
WebContent
WEB-INF
View
TestPage.jsp
other JSP pages...
所以我必须更新struts.xml中的所有结果标记
So I have to update all result tag in struts.xml
<result name="success">/View/TestPage.jsp</result>
到
<result name="success">/WEB_INF/View/TestPage.jsp</result>
在web上搜索后,我发现了一个插件 - struts约定插件来实现这一点,但它遵循它的命名约定。
After search on web I found a plugin - struts convention plugin to achieve this, But it follows its Naming convention.
我可以重写Struts约定插件配置(不会遵循它的命名约定)?我也试过,但它没有反映。我的 struts.xml
是
Can I override Struts convention plugin configuration (that will not follow its naming convention)?I have tried too, but it is not reflecting. My struts.xml
is
<struts>
<constant name="struts.devMoade" value="true" />
<constant name="struts.convention.result.path" value="/WEB-INF/View/" />
<package name="test" extends="struts-default" namespace="/">
<action name="hello1" class="testAction.Hello1Action">
<result name="success">/TestPage.jsp</result>
</action>
</package>
</struts>
当我运行
localhost:8080/project-name/hello1
显示错误404.But如果我改变struts.xml中的结果为
It displays error 404.But if I change result in struts.xml as
<result name="success">/WEB-INF/View/TestPage.jsp</result>
效果很好。
推荐答案
常规插件使用不同的配置提供程序,此常数仅适用于按惯例创建的配置。
The convention plugin uses a different configuration provider and this constant only works with configuration created by convention.
<constant name="struts.convention.result.path" value="/WEB-INF/View/" />
如果要覆盖约定配置,则应使用注释。
If you want to override the convention configuration you should use annotations.
package testAction;
@ParentPackage("json-default")
@Namespace("/")
@Action(value="hello1", results=@Result(name = "success", location="TestPage.jsp"))
public class Hello1Action extends ActionSupport {
}
这篇关于struts.convention.result.path在Struts2中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!