1

我目前的項目結構如下struts.convention.result.path不能在Struts2工作

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

我的任務是把文件夾WEB-INF內的所有JSP頁面和做的相對變化項目。

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.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.But如果我在struts.xml的改變的結果

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

它工作正常。

我不想在所有結果標籤中進行更改。如何通過在一個位置進行更改來實現此目的?

+0

如果您已經閱讀過鏈接問題,爲什麼您根據此問題中接受的答案設置了錯誤的位置? – 2015-02-06 11:45:51

+0

我也試過,但沒有工作。 – 2015-02-06 11:55:57

回答

0

約定插件使用不同的配置提供程序,此常量僅適用於通過約定創建的配置。

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

如果你想重寫約定配置,你應該使用註釋。

package testAction; 

@ParentPackage("json-default") 
@Namespace("/") 
@Action(value="hello1", [email protected](name = "success", location="TestPage.jsp")) 
public class Hello1Action extends ActionSupport { 
} 
+0

我們不能通過配置文件 - struts.xml來使用它嗎? – 2015-02-09 08:31:11

+0

您在'struts.xml'中寫入的常量,操作配置寫入註釋中。來自'struts.xml'的動作配置刪除。 – 2015-02-09 08:35:07

+0

我們不能在struts.xml中使用動作配置而不是註釋嗎? – 2015-02-09 08:36:46