最大的網(wǎng)站源碼資源下載站,
velocity |
變量定義:用$標(biāo)志 表達(dá)式語句:以#開始 強(qiáng)控制語言:變量賦值:#set $this = "velocity" 外部引用:#include ( $1 ) 條件控制:#if …. #end 非兼容語言 |
jdynamite 變量定義:用{}包裝 表達(dá)式語句:寫在注釋格式(<!-- à)中 弱控制語言 兼容語言 |
xslt 變量定義:xml標(biāo)簽 表達(dá)式:xsl標(biāo)簽 強(qiáng)控制語言:外部引用:import,include 條件控制:if, choose…when…otherwise 非兼容語言 |
tapestry 采用component的形式開發(fā)。 變量定義(組件定義):在html標(biāo)簽中加上jwcid 表達(dá)式語句:ognl規(guī)范 兼容語言 |
example.vm: hello from $name in the $project project. example.java: velocitycontext context = new velocitycontext(); context.put("name", "velocity"); context.put("project", "jakarta"); |
velocity |
template template = velocity.gettemplate("test.wm"); context context = new velocitycontext(); context.put("foo", "bar"); context.put("customer", new customer()); template.merge(context, writer); 當(dāng)調(diào)用velocity.gettemplate 方法時(shí),將調(diào)用resourcemanger的對(duì)應(yīng)方法。 resourcemanger先查看該模板文件是否在cache中,如果沒有就去獲取,生成resource對(duì)象并調(diào)用process()方法,確定該模板是否有效,如果有效,則在內(nèi)存中生成一個(gè)node樹。 當(dāng)調(diào)用template.merge()時(shí),遍歷這顆node樹,并調(diào)用每個(gè)node的render方法。對(duì)于模板中的變量和對(duì)象node,還將調(diào)用execute()方法,從context中取得value。 注:resourcemanger在runtime/resource包下,node在runtime/parser/node包下 |
tapestry |
tapestry比較麻煩,先介紹一下http請(qǐng)求的處理過程。 當(dāng)httprequest請(qǐng)求到達(dá)時(shí)。該請(qǐng)求被applicationservlet捕獲,隨后applicationservlet通過getengine取到對(duì)應(yīng)的engine,通過該engine的getservice拿到對(duì)應(yīng)的service,調(diào)用其service方法執(zhí)行http請(qǐng)求。 每個(gè)service通過requestcycle對(duì)象的getpage方法取得page對(duì)象,并將其設(shè)置為該cycle對(duì)象的active page。之后service調(diào)用renderresponse方法執(zhí)行輸出。 renderresponse調(diào)用page的getresponsewriter(output)取得writer對(duì)象,并把它傳給cycle.renderpage(writer)方法,該方法調(diào)用page的renderpage方法。 page執(zhí)行renderpage時(shí),首先判斷是否有l(wèi)istener的請(qǐng)求,如果有則處理listener請(qǐng)求;然后調(diào)用basecomponenttemplateloader的process方法把模板文件載入并形成一個(gè)component節(jié)點(diǎn)樹,依次執(zhí)行節(jié)點(diǎn)的rendercomponent方法。 每個(gè)component對(duì)象將通過ongl的機(jī)制取得對(duì)象屬性。并把該值寫入輸入流。 例如:insert component protected void rendercomponent(imarkupwriter writer, irequestcycle cycle) { if (cycle.isrewinding()) return; object value = getvalue(); if (value == null) return; string insert = null; format format = getformat(); if (format == null) { insert = value.tostring(); } else{ try{ insert = format.format(value); } catch (exception ex) { throw new applicationruntimeexception( tapestry.format("insert.unable-to-format",value),this, getformatbinding().getlocation(), ex); } } string styleclass = getstyleclass(); if (styleclass != null) { writer.begin("span"); writer.attribute("class", styleclass); renderinformalparameters(writer, cycle); } if (getraw()) writer.printraw(insert); else writer.print(insert); if (styleclass != null) writer.end(); // <span> } getvalue為取得insert的value屬性。 |
test.jsp: <html> <head><title>jsp test</title></head> <body> <table width="226" border="0" cellspacing="0" cellpadding="0"> <tr><td><font face="arial" size="2" color="#000066"> <b class="headlinebold">the jsp test file</b> </tr></td> </font> </table> <body> </html> |
test_jsp.java: package org.apache.jsp; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import org.apache.jasper.runtime.*; public class test _jsp extends httpjspbase { private static java.util.vector _jspx_includes; public java.util.list getincludes() { return _jspx_includes; } public void _jspservice(httpservletrequest request, httpservletresponse response) throws java.io.ioexception, servletexception { jspfactory _jspxfactory = null; javax.servlet.jsp.pagecontext pagecontext = null; httpsession session = null; servletcontext application = null; servletconfig config = null; jspwriter out = null; object page = this; jspwriter _jspx_out = null; try { _jspxfactory = jspfactory.getdefaultfactory(); response.setcontenttype("text/html;charset=iso-8859-1"); pagecontext = _jspxfactory.getpagecontext(this, request, response, null, true, 8192, true); application = pagecontext.getservletcontext(); config = pagecontext.getservletconfig(); session = pagecontext.getsession(); out = pagecontext.getout(); _jspx_out = out; out.write("<html>/r/n"); out.write("<head><title>jsp test</title></head> /r/n"); out.write("<body>/r/n"); out.write("<table width=/"226/" border=/"0/" cellspacing=/"0/" cellpadding=/"0/">/r/n "); out.write("<tr><td><font face=/"arial /" size=/"2/" color=/"#000066/"> /r/n/t "); out.write("<b class=/"headlinebold/">the jsp test file"); out.write("</b>/r/n/t "); out.write("</tr></td></font>/r/n/t "); out.write("</table>/r/n"); out.write("<body>/r/n"); out.write("</html>"); } catch (throwable t) { out = _jspx_out; if (out != null && out.getbuffersize() != 0) out.clearbuffer(); if (pagecontext != null) pagecontext.handlepageexception(t); } finally { if (_jspxfactory != null) _jspxfactory.releasepagecontext(pagecontext); } } } |
tag類為: package my.customtags; import javax.servlet.jsp.jspwriter; import javax.servlet.jsp.pagecontext; import javax.servlet.jsp.tagext.tagsupport; public class hidden extends tagsupport{ string name; public hidden(){ name = ""; } public void setname(string name){ this.name = name; } public void release(){ value = null; } public int dostarttag(){ return eval_body_include;} public int doendtag() throws jsptagexception{ try{ pagecontext.getout().write(", you are welcome"); } catch(ioexception ex){ throw new jsptagexception("error!"); } return eval_page; } } jsp頁面: <my:hidden name="testname"/> 生成的jsp代碼: my.customtags.hidden _jspx_th_my_hidden_11 = (my.customtags.hidden) _jspx_tagpool_my_hidden_name.get(my.customtags.hidden.class); _jspx_th_my_hidden_11.setpagecontext(pagecontext); _jspx_th_my_hidden_11.setparent(null); _jspx_th_my_hidden_11.setname("testname"); int _jspx_eval_my_hidden_11 = _jspx_th_my_hidden_11.dostarttag(); if (_jspx_th_my_hidden_11.doendtag() == javax.servlet.jsp.tagext.tag.skip_page) return true; _jspx_tagpool_my_hidden_name.reuse(_jspx_th_my_hidden_11); return false; |
velocity: turbine項(xiàng)目(http://jakarta.apache.org/turbine)采用了velocity技術(shù)。 1. 友好性不夠。理由: 強(qiáng)控制類型,出現(xiàn)頁面顯示控制代碼和html混合。與html的不兼容,無法所見即所得。遇到大的html頁面,從一個(gè) “#if”找到對(duì)應(yīng)的 “#end”也是很痛苦的一件事情。 2. 表現(xiàn)力強(qiáng)。理由:強(qiáng)控制語言。 3. 復(fù)用性弱。理由:模板腳本和頁面代碼混合。 |
xslt cocoon項(xiàng)目(http://cocoon.apache.org/)采用xml + xslt的方法。csdn社區(qū)也是采用此方案。 1. 內(nèi)容和顯示風(fēng)格分離,這點(diǎn)xslt做的最好。 2. 速度慢。理由:xslt的使用xpath,由于是要解析dom樹,當(dāng)xml文件大時(shí),速度很慢。 3. 友好性不夠。理由:由于沒有html文件,根本看不到頁面結(jié)構(gòu)、顯示風(fēng)格和內(nèi)容。xsl語法比較難以掌握,由于沒有“所見即所得”編輯工具,學(xué)習(xí)成本高。 4. 表現(xiàn)力強(qiáng)。理由:強(qiáng)控制語言。 5. 復(fù)用性弱。理由:xsl標(biāo)簽和html標(biāo)簽混合。 |
jdynamite 1. 表現(xiàn)力中等。理由:弱控制語言。 2. 友好性強(qiáng)。理由:所見即所得的效果。在模板件中的ignore block在編輯條件下可展示頁面效果,而在運(yùn)行中不會(huì)被輸出。 3. 復(fù)用性強(qiáng)。理由:利用html標(biāo)簽。 |
tapestry 1. 友好性中等。理由:整個(gè)tapestry頁面文件都是html元素。但是由于component會(huì)重寫html標(biāo)簽,其顯示的樣子是否正確,將不預(yù)測(cè)。 2. 表現(xiàn)力強(qiáng)。理由:強(qiáng)控制語言。 3. 復(fù)用性強(qiáng)。理由:擴(kuò)展了html元素的定義。 |
新聞熱點(diǎn)
疑難解答
圖片精選