struts設定檔l中使用include 標籤 引入另外一個在jar中的struts檔案

來源:互聯網
上載者:User

最近遇到了一個需求:有一個master struts.xml, 該檔案中需要引入若該子模組中struts.xml.

但是這些子模組都以jar包的方式放入主模組的classpath中,當然它們的struts.xml也在jar中, 這種情形主模組的struts還能引入嗎?

首先問問google,結果是可行, 如下來自struts官方網站:

<!DOCTYPE struts PUBLIC  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  "http://struts.apache.org/dtds/struts-2.0.dtd"><struts>    <include file="Home.xml"/>    <include file="Hello.xml"/>    <include file="Simple.xml"/>    <include file="/util/POJO.xml"/>    <include file="/com/initech/admin/admin-struts.xml"/></struts>

Each included file must be in the same format as struts.xml, including the
DOCTYPE. The include files can be placed anywhere on the classpath and should be referred to by that path by the "file" attribute.

開始嘗試:

子模組的struts設定檔 名為test-struts.xml, 路徑為com/strutsTest/myTest/

1. 在主struts設定檔中使用include標籤,並填入全路徑, 如下。

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"><struts><include file="struts-default.xml" /><include file="com/strutsTest/myTest/test-struts.xml" /></struts>

結果:撲街

2. 在主struts設定檔中使用include標籤,只填入檔案名稱, 如下。

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"><struts><include file="struts-default.xml" /><include file="test-struts.xml" /></struts>

結果:撲街

3. 在主struts設定檔中使用include標籤,只填入檔案名稱 並將子模組中的struts設定檔放入jar的頂級路徑中, 即:

childModule.jar-com        --strutsTest              --.....test-struts.xml

主struts設定檔與2相同

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"><struts><include file="struts-default.xml" /><include file="test-struts.xml" /></struts>

結果: 成功!

可是為什麼呢,暫記錄,等有時間解釋,並期待大牛的答疑。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.