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

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

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

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

    在Spring中如何使用Freemarker

    Posted on 2006-12-20 15:18 閱讀(780) 評(píng)論(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>?

    主站蜘蛛池模板: 日韩一级视频免费观看| 最近的中文字幕大全免费8| 天堂在线免费观看中文版| 亚洲精品第一综合99久久| 亚洲三级高清免费| 亚洲人成在线播放| 最近中文字幕mv免费高清电影| 中文无码亚洲精品字幕| 在线观看免费宅男视频| 看成年女人免费午夜视频| 免费国产成人午夜私人影视| 国产偷国产偷亚洲高清在线| 亚洲七七久久精品中文国产| 黄视频在线观看免费| 国产亚洲精品无码专区| 久久精品国产免费| 78成人精品电影在线播放日韩精品电影一区亚洲 | 免费无码H肉动漫在线观看麻豆| 亚洲开心婷婷中文字幕| 一区二区免费视频| 亚洲五月综合缴情婷婷| 最近的中文字幕大全免费版| 免费的黄色的网站| 亚洲AV综合色区无码另类小说| 国产无人区码卡二卡三卡免费| 久久亚洲AV成人无码国产电影 | 亚洲综合在线成人一区| 最新欧洲大片免费在线| 国产精品亚洲va在线观看| 亚洲中文字幕无码爆乳av中文 | 亚洲精品宾馆在线精品酒店| 免费在线观看理论片| a毛片全部播放免费视频完整18| 久久精品亚洲精品国产色婷| 日本二区免费一片黄2019| 美女被免费网站91色| 亚洲AV色吊丝无码| 4338×亚洲全国最大色成网站| 最近中文字幕国语免费完整 | 国产精品日本亚洲777| 久久亚洲精品成人综合|