<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Struts2 – 如何正確設置結果路徑 > 原文: [https://howtodoinjava.com/struts2/how-to-correctly-set-result-path-in-struts-2/](https://howtodoinjava.com/struts2/how-to-correctly-set-result-path-in-struts-2/) 在這里,結果路徑表示 Struts2 在執行 Action 類中的代碼后將解析的 JSP 文件或其他視圖文件的位置。 這些**結果路徑在`Action`類頂部的`@Result`注解**的“位置”中提到。 一旦動作類完成執行,它將把控件傳遞給視圖解析器。 視圖解析器嘗試查找需要渲染的視圖文件的位置。 該解決方案主要可以通過兩種方式提及: ## 1)將整個相對路徑添加到“位置”屬性 現在,在這里,一個簡單的“`/`”可以改變整個含義,所以要小心。 **A)在位置屬性中帶有“`/`”字符** ```java @Namespace("/default") @Results({ @Result(name="success", location="/WEB-INF/jsp/success.jsp"), @Result(name="input", location="/WEB-INF/jsp/index.jsp") }) public class TestAction extends ActionSupport { //More code... } ``` 上面的定義會將 jsp 文件的位置解析為:: ```java %PROJECT_PATH%/WEB-INF/jsp/success.jsp ``` **B)位置屬性中沒有“`/`”字符** ```java @Namespace("/default") @Results({ @Result(name="success", location="WEB-INF/jsp/success.jsp"), @Result(name="input", location="WEB-INF/jsp/index.jsp") }) public class TestAction extends ActionSupport { //More code... } ``` 上面的定義會將jsp文件的位置解析為: ```java %PROJECT_PATH%/WEB-INF/content/WEB-INF/jsp/index.jsp ``` **原因**:背后的原因是,開始時的“`/`”在項目根處解析,而其余路徑在項目根目錄下解析。 但是,**當不在開始時使用“`/`”時,默認的根目錄假定為“`/WEB-INF/content`”文件夾**,其余的路徑與此相對。 因此,當您下次注意時,請在`@Result`注解中指定`location`屬性。 ## 2)將資源根路徑定義為常量“`struts.convention.result.path`” 您可以在此常量中定義資源的固定部分,即 JSP 文件,然后只需指定 jsp 文件的名稱即可,而不必擔心其在項目中的位置。 **另一個優點是,您以后可以將視圖文件移動到其他文件夾中**,甚至**重命名文件夾名稱**,而不必擔心其影響。 您只需要更改此常數中的路徑。 可以在`struts.xml`中將該常量定義為: ```java <struts> <constant name="struts.convention.result.path" value="/WEB-INF/jsp/" /> </struts> ``` 在`struts.properties`文件中為: ```java struts.convention.result.path=/WEB-INF/jsp/ ``` 指定此常量后,在`Action`類中,我們只需要指定 JSP 文件名即可。 ```java @Namespace("/default") @Results({ @Result(name="success", location="success.jsp"), @Result(name="input", location="index.jsp") }) public class TestAction extends ActionSupport { //More code... } ``` 推薦使用涉及常量“`struts.convention.result.path`”的第二種方法。 **祝您學習愉快!**
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看