<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    即使世界明天毀滅,我也要在今天種下我的葡萄樹。
    posts - 112, comments - 14, trackbacks - 0, articles - 11

    在Spring中如何使用Freemarker

    Posted on 2006-12-20 15:18 閱讀(780) 評論(0)  編輯  收藏 所屬分類: XML Design
    在Spring中如何使用Freemarker
    1. Copy freemarker.jar (from the lib directory of the FreeMarker distribution) into the WEB-INF/lib directory of your Web application.
    2. Insert the following section to the WEB-INF/web.xml file of your Web application (and adjust it if required):

    <servlet>

    ? <servlet-name>freemarker</servlet-name>

    ? <servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class>

    ???

    ? <!-- FreemarkerServlet settings: -->

    ? <init-param>

    ??? <param-name>TemplatePath</param-name>

    ??? <param-value>/</param-value>

    ? </init-param>

    ? <init-param>

    ??? <param-name>NoCache</param-name>

    ??? <param-value>true</param-value>

    ? </init-param>

    ? <init-param>

    ??? <param-name>ContentType</param-name>

    ??? <param-value>text/html</param-value>

    ? </init-param>

    ???

    ? <!-- FreeMarker settings: -->

    ? <init-param>

    ??? <param-name>template_update_delay</param-name>

    ??? <param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. -->

    ? </init-param>

    ? <init-param>

    ??? <param-name>default_encoding</param-name>

    ??? <param-value>ISO-8859-1</param-value>

    ? </init-param>

    ? <init-param>

    ??? <param-name>number_format</param-name>

    ??? <param-value>0.##########</param-value>

    ? </init-param>

    ?

    ? <load-on-startup>1</load-on-startup>

    </servlet>

    ?

    <servlet-mapping>

    ? <servlet-name>freemarker</servlet-name>

    ? <url-pattern>*.ftl</url-pattern>

    </servlet-mapping>?

    That's all. After this, you can use FTL files ( *.ftl ) in the same manner as JSP ( *.jsp ) files. (Of course you can choose another extension besides ftl ; it is just the convention)

    Note

    How does it work? Let's examine how JSP-s work. Many servlet container handles JSP-s with a servlet that is mapped to the *.jsp request URL pattern. That servlet will receive all requests where the request URL ends with .jsp , find the JSP file based on the request URL, and internally compiles it to a Servlet , and then call the generated servlet to generate the page. The FreemarkerServlet mapped here to the *.ftl URL pattern does the same, except that FTL files are not compiled to Servlet -s, but to Template objects, and then the process method of Template will be called to generate the page.

    For example, instead of this JSP file (note that it heavily uses Struts tag-libs to save designers from embedded Java monsters):

    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

    ?

    <html>

    <head><title>Acmee Products International</title>

    <body>

    ? <h1>Hello <bean:write name="user"/>!</h1>

    ? <p>These are our latest offers:

    ? <ul>

    ??? <logic:iterate name="latestProducts" id="prod">

    ????? <li><bean:write name="prod" property="name"/>

    ??????? for <bean:write name="prod" property="price"/> Credits.

    ??? </logic:iterate>

    ? </ul>

    </body>

    </html>?

    you can use this FTL file (use ftl file extension instead of jsp ):

    <html>

    <head><title>Acmee Products International</title>

    <body>

    ? <h1>Hello ${user}!</h1>

    ? <p>These are our latest offers:

    ? <ul>

    ??? <#list latestProducts as prod>

    ????? <li>${prod.name} for ${prod.price} Credits.

    ??? </#list>

    ? </ul>

    </body>

    </html>?

    主站蜘蛛池模板: 在线视频免费观看爽爽爽| 国产成人综合亚洲亚洲国产第一页| 国产午夜亚洲精品| 亚洲国产天堂久久久久久| 两个人看的www高清免费观看| 亚洲国产av一区二区三区丶| 免费永久看黄在线观看app| 一区二区三区无码视频免费福利| 激情综合亚洲色婷婷五月APP| 亚洲国产综合无码一区二区二三区| 99视频精品全部免费观看| 综合偷自拍亚洲乱中文字幕| 久久久综合亚洲色一区二区三区| 免费看的黄色大片| 免费人成在线观看网站| 爱爱帝国亚洲一区二区三区| 亚洲av丰满熟妇在线播放| 亚洲AV蜜桃永久无码精品| 国产成人精品免费午夜app| 在线播放国产不卡免费视频| 亚洲人成免费网站| 国产精品亚洲片在线| 国产在线播放免费| 无码av免费毛片一区二区| 久久免费视频一区| 在线观看亚洲网站| 亚洲一级黄色大片| 国产成人亚洲综合色影视| 国产成人免费永久播放视频平台| 57pao国产成视频免费播放| 老司机精品免费视频| 亚洲国产aⅴ成人精品无吗| 中文字幕亚洲免费无线观看日本| 亚洲日韩中文字幕日韩在线| 免费观看理论片毛片| 4hu四虎最新免费地址| 日韩免费在线观看视频| 美女扒开屁股让男人桶爽免费| 亚洲专区一路线二| 久久亚洲AV成人无码软件| 亚洲VA中文字幕不卡无码|