欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來(lái)到入門(mén)教程網(wǎng)!

JSP編程

當(dāng)前位置:主頁(yè) > 網(wǎng)絡(luò)編程 > JSP編程 >

jsp中sitemesh修改tagRule技術(shù)分享

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-11|欄目:JSP編程|點(diǎn)擊: 次

sitemesh默認(rèn)提供了一些常用的rule

可以看到其實(shí)可以選擇

/**
 * Extracts the contents of any elements that look like
 * <code><content tag='foo'>...</content></code> and write the contents
 * to a page property (page.foo).
 *
 * <p>This is a cheap and cheerful mechanism for embedding multiple components in a
 * page that can be used in different places in decorators.</p>
 *
 * @author Joe Walnes
 */
public class ContentBlockExtractingRule extends BasicBlockRule<String> {
 private final ContentProperty propertyToExport;
 public ContentBlockExtractingRule(ContentProperty propertyToExport) {
  this.propertyToExport = propertyToExport;
 }
 @Override
 protected String processStart(Tag tag) throws IOException {
  tagProcessorContext.pushBuffer();
  return tag.getAttributeValue("tag", false);
 }
 @Override
 protected void processEnd(Tag tag, String tagId) throws IOException {
  propertyToExport.getChild(tagId).setValue(tagProcessorContext.currentBufferContents());
  tagProcessorContext.popBuffer();
 }
}

修改ScriptTagRuleBundle處理如下

public class ScriptTagRuleBundle implements TagRuleBundle {
 @Override
 public void install(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {
  defaultState.addRule("content", new ContentBlockExtractingRule(contentProperty.getChild("page")));
 }
 @Override
 public void cleanUp(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {
 }
}

用法很簡(jiǎn)單使用content作為tag默認(rèn)填上tag即可

比如

<content tag="reference">
<script type="text/javascript" src="<%=path%>/plugins/select2/js/select2.min.js"></script>
<script type="text/javascript" src="<%=path%>/plugins/select2/js/i18n/zh-CN.js"></script>
<script type="text/javascript" src="<%=path%>/plugins/bootstrap-modal/js/bootstrap-modal.js"></script>
<script type="text/javascript" src="<%=path%>/plugins/bootstrap-modal/js/bootstrap-modalmanager.js"></script>
</content>

模板中這樣

<body class="mainBody">
<sitemesh:write property='body'/>
<sitemesh:write property='page.reference'/>
</body>

這樣就可以很簡(jiǎn)單的放入到任意位置?。?!

弊端

這樣雖然很簡(jiǎn)單 但是也存在一些問(wèn)題 開(kāi)發(fā)如果需要增加新的content必須要要到母版頁(yè)【對(duì)的 其實(shí)sitemesh不就像是asp.net中的母版頁(yè)么】

增加對(duì)應(yīng)的sitemesh:write標(biāo)簽

propertyToExport.getChild(tagId).setValue(tagProcessorContext.currentBufferContents());

并且上述代碼中同樣存在覆蓋的問(wèn)題 比如多處使用了同樣的tagId

解決

sitemesh似乎沒(méi)有提供直接用來(lái)拼接多個(gè)的tagRule

如果有需求將某塊元素放入到末尾 可以考慮增加tagRule

在processEnd時(shí)直接將對(duì)應(yīng)的元素直接append

最終可以直接輸出

以上就是我們給大家整理的本次教程的全部?jī)?nèi)容,感謝你對(duì)我們的支持。

上一篇:秒殺系統(tǒng)Web層設(shè)計(jì)的實(shí)現(xiàn)方法

欄    目:JSP編程

下一篇:JSP的setProperty的使用方法

本文標(biāo)題:jsp中sitemesh修改tagRule技術(shù)分享

本文地址:http://mengdiqiu.com.cn/a1/JSPbiancheng/11438.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有