最大的網站源碼資源下載站,
velocity |
變量定義:用$標志 表達式語句:以#開始 強控制語言:變量賦值:#set $this = "velocity" 外部引用:#include ( $1 ) 條件控制:#if …. #end 非兼容語言 |
jdynamite 變量定義:用{}包裝 表達式語句:寫在注釋格式(<!-- à)中 弱控制語言 兼容語言 |
xslt 變量定義:xml標簽 表達式:xsl標簽 強控制語言:外部引用:import,include 條件控制:if, choose…when…otherwise 非兼容語言 |
tapestry 采用component的形式開發。 變量定義(組件定義):在html標簽中加上jwcid 表達式語句:ognl規范 兼容語言 |
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); 當調用velocity.gettemplate 方法時,將調用resourcemanger的對應方法。 resourcemanger先查看該模板文件是否在cache中,如果沒有就去獲取,生成resource對象并調用process()方法,確定該模板是否有效,如果有效,則在內存中生成一個node樹。 當調用template.merge()時,遍歷這顆node樹,并調用每個node的render方法。對于模板中的變量和對象node,還將調用execute()方法,從context中取得value。 注:resourcemanger在runtime/resource包下,node在runtime/parser/node包下 |
tapestry |
tapestry比較麻煩,先介紹一下http請求的處理過程。 當httprequest請求到達時。該請求被applicationservlet捕獲,隨后applicationservlet通過getengine取到對應的engine,通過該engine的getservice拿到對應的service,調用其service方法執行http請求。 每個service通過requestcycle對象的getpage方法取得page對象,并將其設置為該cycle對象的active page。之后service調用renderresponse方法執行輸出。 renderresponse調用page的getresponsewriter(output)取得writer對象,并把它傳給cycle.renderpage(writer)方法,該方法調用page的renderpage方法。 page執行renderpage時,首先判斷是否有listener的請求,如果有則處理listener請求;然后調用basecomponenttemplateloader的process方法把模板文件載入并形成一個component節點樹,依次執行節點的rendercomponent方法。 每個component對象將通過ongl的機制取得對象屬性。并把該值寫入輸入流。 例如: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項目(http://jakarta.apache.org/turbine)采用了velocity技術。 1. 友好性不夠。理由: 強控制類型,出現頁面顯示控制代碼和html混合。與html的不兼容,無法所見即所得。遇到大的html頁面,從一個 “#if”找到對應的 “#end”也是很痛苦的一件事情。 2. 表現力強。理由:強控制語言。 3. 復用性弱。理由:模板腳本和頁面代碼混合。 |
xslt cocoon項目(http://cocoon.apache.org/)采用xml + xslt的方法。csdn社區也是采用此方案。 1. 內容和顯示風格分離,這點xslt做的最好。 2. 速度慢。理由:xslt的使用xpath,由于是要解析dom樹,當xml文件大時,速度很慢。 3. 友好性不夠。理由:由于沒有html文件,根本看不到頁面結構、顯示風格和內容。xsl語法比較難以掌握,由于沒有“所見即所得”編輯工具,學習成本高。 4. 表現力強。理由:強控制語言。 5. 復用性弱。理由:xsl標簽和html標簽混合。 |
jdynamite 1. 表現力中等。理由:弱控制語言。 2. 友好性強。理由:所見即所得的效果。在模板件中的ignore block在編輯條件下可展示頁面效果,而在運行中不會被輸出。 3. 復用性強。理由:利用html標簽。 |
tapestry 1. 友好性中等。理由:整個tapestry頁面文件都是html元素。但是由于component會重寫html標簽,其顯示的樣子是否正確,將不預測。 2. 表現力強。理由:強控制語言。 3. 復用性強。理由:擴展了html元素的定義。 |
新聞熱點
疑難解答