【问题标题】:Struts 2 action method and struts.convention.result.path not workingStruts 2 动作方法和 struts.convention.result.path 不起作用
【发布时间】:2013-09-18 19:20:39
【问题描述】:

我对 Struts2 操作方法和 struts.convention.result.path 有疑问 这是我的struts.xml

<struts>
    <constant name="struts.action.extension" value="" />
    <constant name="struts.action.excludePattern" value="/.*\.(html|jsp),/static/.*"/>
    <constant name="struts.convention.result.path" value="/WEB-INF/pages/" />
    <package name="user" namespace="/user" extends="struts-default">
        <action name="login" class="loginAction" method="login">
            <result name="success">login.jsp</result>
        </action>
    </package>
<struts>

当我运行 url "localhost:8080/venus/user/login"。它显示错误"HTTP Status 404 - /venus/user/login.jsp"

如果我将login() 方法更改为execute() 方法,它就可以工作。 或者,如果我更改为 &lt;result name="success"&gt;/WEB-INF/pages/login.jsp&lt;/result&gt;,它可以工作。

谁能解释并教我如何在 xml 中使用带有结果路径配置的操作方法? 非常感谢!

【问题讨论】:

  • 使用Convention插件时,不需要xml配置。

标签: java configuration struts2 action actionresult


【解决方案1】:

您应该指定绝对路径名。

<result name="success">/login.jsp</result>

【讨论】:

    【解决方案2】:

    使用Convention插件时,不需要xml配置:

    • com.mycompany.actions.user -> 命名空间“用户”
    • Lo​​ginAction -> login.action
    • Lo​​ginAction#execute -> 成功 -> 用户/login.jsp
    • Lo​​ginAction#login -> 成功 -> 用户/登录(-login|-success).jsp

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-20
      • 1970-01-01
      • 2014-05-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多