1

我目前的项目结构如下

WebContent
   WEB-INF
   View
     TestPage.jsp
     other JSP pages...

我的任务是将所有 JSP 页面放在文件夹 WEB-INF 中,并在项目中进行所有相关更改。

WebContent
   WEB-INF
      View
        TestPage.jsp
        other JSP pages...

所以我必须更新 struts.xml 中的所有结果标签

<result name="success">/View/TestPage.jsp</result>

<result name="success">/WEB_INF/View/TestPage.jsp</result>

在网上搜索后,我找到了一个插件 - struts 约定插件来实现这一点,但它遵循其命名约定。

我可以覆盖 Struts 约定插件配置(不遵循其命名约定)吗?我也尝试过,但它没有反映。我struts.xml的是

<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。但是如果我将 struts.xml 中的结果更改为

<result name="success">/WEB-INF/View/TestPage.jsp</result>

它工作正常。

我不想对所有结果标签进行更改。如何通过在一个地方进行更改来实现这一点?

4

1 回答 1

0

约定插件使用不同的配置提供程序,并且此常量仅适用于约定创建的配置。

<constant name="struts.convention.result.path" value="/WEB-INF/View/" />

如果要覆盖约定配置,则应使用注释。

package testAction;

@ParentPackage("json-default")
@Namespace("/")
@Action(value="hello1", results=@Result(name = "success", location="TestPage.jsp"))
public class Hello1Action extends ActionSupport {
}
于 2015-02-07T10:51:18.670 回答