【问题标题】:struts.convention.result.path is not working in Struts2struts.convention.result.path 在 Struts2 中不起作用
【发布时间】:2015-02-06 10:44:47
【问题描述】:

我目前的项目结构如下

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>

效果很好。

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

【问题讨论】:

  • 如果您已阅读链接问题,为什么根据此问题中接受的答案设置错误的位置?
  • 我也试过了,但是不行。

标签: java configuration struts2 action struts2-convention-plugin


【解决方案1】:

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

<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 {
}

【讨论】:

  • 不能通过配置文件-struts.xml来使用吗?
  • struts.xml中写的常量,注解中写的动作配置。 struts.xmlremove 的动作配置。
  • 我们不能在struts.xml中使用action配置来代替注解吗?
  • 你可以使用动作配置,但它不适用于上面的常量。
  • 如果你想使用约定插件的注释覆盖来自struts.xml的动作配置,不,你不能。这是这里的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-05-25
  • 2012-04-09
  • 2011-05-24
  • 2011-01-26
  • 2013-02-04
  • 1970-01-01
  • 2012-10-13
相关资源
最近更新 更多