修改Struts2預設的模板配置

來源:互聯網
上載者:User
在用struts2開發項目的時候發現它總是會添加一些html標籤在最終產生的html代碼中,比如說使用<s:form></s:form>標籤,此時產生的html代碼如下:
<form ...><table class="wwFormTable"></table></form>
其中藍色高亮部分是struts自動產生的,對於這些自動產生的東西有時候有用,但是對於有些項目確是不合適的,比如說我們的頁面全部不允許加入table標籤,或者需要用別的樣式單等等,此時我們就希望不要產生這些多餘的標籤。
那麼怎樣才能讓struts2不要產生這些標籤呢?
其實在struts-core-2.06.jar的包中包含了一些預設的模版檔案,它們位於${struts-core-2.06.jar}/template下,其中有ajax,simple,xhtml等。
查看一下struts.properties如果沒有可以查看${struts-core-2.06.jar}/org/apache/struts2/default.properties檔案,其中有如下配置:
struts.ui.theme=xhtml
struts.ui.templateDir=template
struts.ui.templateSuffix=ftl
這一段就是關於struts2模版的配置資訊,我們可以修改struts.properties檔案,將其改成
struts.ui.theme=simple
struts.ui.templateDir=template
struts.ui.templateSuffix=ftl
如果沒有struts.properties檔案,可以修改struts.xml檔案,在其中加入如下行
<constant name="struts.ui.theme" value="simple" />
<constant name="struts.ui.templateDir" value="template" />
<constant name="struts.ui.templateSuffix" value="ftl" />
此時<s:form></s:form>標籤產生的html代碼將會是<form ...></form>。 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.