FreeMarker是一个用Java编写的模板引擎,主要用来生成HTML Web页面,特别是基于MVC模式的应用程序。虽然FreeMarker具有一些编程的能力,但不像PHP,通常由Java程序准备要显示的数据,由FreeMarker模板生成页面。
FreeMarker可以作为Web应用框架一个组件,但它与容器无关,在非Web应用程序环境也能工作的很好。
FreeMarker适合作为MVC的视图组件,还能在模板中使用JSP标记库。
- <html>
- <head>
- <title>Welcome!</title>
- </head>
- <body>
- <h1>Welcome${user}!</h1>
- <p>Ourlatestproduct:
- <ahref="${latestProduct.url}">${latestProduct.name}</a>!
- </body>
- </html>
- <html>
- <head>
- <title>Welcome!</title>
- </head>
- <body>
- <h1>Welcome${user}!</h1>
- <p>Ourlatestproduct:
- <ahref="${latestProduct.url}">${latestProduct.name}</a>!
- </body>
- </html>
上面的例子中,在简单的HTML中加入了一些由${…}包围的特定FreeMarker的指令,这个文件就称为模板了。而user、latestProduct.url和latestProduct.name来自于数据模型,由Java程序提供,模板设计者就不用关心数据从哪来的。
FreeMarker模板中可以包括下面四种特定部分: 一)文本:直接输出
二)FTL标记(FreeMarker模板语言标记):类似于HTML标记,名字前加#(有些以@开始,用户自定义标记)予以区分,不会输出。
1.字符串:使用单引号或双引号限定;如果包含特殊字符需要转义符:${"It's /"quoted/" andthis is a backslash: //"}
有一类特殊的字符串:${r"C:/foo/bar"},输出结构为:C:/foo/bar,在引号前面加r被认为是纯文本。
2.数字:直接输入,不需要引号。${08}, ${+8}, ${8.00} and ${8} 都是相同的
3.布尔值:true和false,不使用引号
4.Sequences(序列)
a.由逗号分隔的变量列表,由方括号限定,类似java中的一维数组:
例一:["winter", "spring", "summer", "autumn"]
例二:[2 + 2, [1, 2, 3, 4], "whatnot"] (可以嵌套)
例三:2..5,等同于[2, 3, 4, 5];5..2,等同于[5,4,3,2]。
注意方括号是不需要的。 (另外写法)
b.获取Sequence(序列)中元素-使用[startindex..endindex]
例如:seq中存储了"a", "b", "c", "d","e",
那么seq[1..2]包含了b和c两个值。
c.Sequences(序列)元素的遍历
<#list ["Joe", "Fred"] + ["Julia", "Kate"] as user>
${user}
</#list> 5.Hashes(散列)
由逗号分隔的键-值列表,由大括号限定,键和值之间用冒号分隔:{"name":"green mouse", "price":150},键和值都是表达式,但是键必须是字符串。
获取变量-${variable},变量名只能是字母、数字、下划线、$、@和#的组合,且不能以数字开头。可以使用.variablename语法访问FreeMarker内置变量。 下列表达式是等价的:
book.author.name
book["author"].name
book.author.["name"]
book["author"]["name"]
6.字符串操作
{"Hello ${user}!"} <==> ${"Hello " + user + "!"}
${"${user}${user}${user}${user}"} <==> ${user + user + user + user}
${…}只能在文本中使用,下面是错误的代码:
<#if ${isBig}>Wow!</#if>
<#if "${isBig}">Wow!</#if> //此处的代码也是错误的,因为if指令需要的是boolean,实际的却是个字符串
子字符串的操作,
<#assign user="Big Joe">
${user[0]}${user[4]} <==> BJ
${user[1..4]} <==> ig J
注意: 操作符两边必须是数字;使用"+"时,如果一边是数字,一边是字符串,就会自动将数字转换为字符串。
7.使用内建的指令int获得整数部分:
${(x/2)?int}
${1.1?int}
${1.999?int}
${-1.1?int}
${-1.999?int}
8.比较操作符-<#if expression>...</#if>
1.)使用=(或==,完全相等)测试两个值是否相等,使用!= 测试两个值是否不相等
2.)=和!=两边必须是相同类型的值,否则会产生错误,例如<#if 1 = "1">会引起错误
3.)Freemarker是精确比较,所以"x"、"x "和"X"是不相等的
4.)对数字和日期可以使用<、<=、>和>=,但不能用于字符串
5.)由于Freemarker会将>解释成FTL标记的结束字符,所以对于>和>=可以使用括号来避免这种情况,例如<#if (x > y)>,另一种替代的方法是,使用lt、lte、gt和gte来替代<、<=、>和>=
6.)逻辑操作符-&&(and)、||(or)、!(not),只能用于布尔值,否则会产生错误
<#if x < 12 && color = "green">
We have less than 12 things, and they are green.
</#if>
<#if !hot> <#-- here hot must be a boolean -->
It's not hot.
</#if>
9.内置函数-用法类似访问hash(散列)的子变量,只是使用"?"替代".",
例如:user?upper_case
下面列出常用的一些函数:
对于字符串 html-对字符串进行HTML编码 cap_first-使字符串第一个字母大写 lower_case-将字符串转换成小写 trim-去掉字符串前后的空白字符
对于Sequences(序列)
size-获得序列中元素的数目
对于数字
int-取得数字的整数部分(如-1.9?int的结果是-1)
10.方法的调用
${repeat("What", 3)}
${repeat(repeat("x", 2), 3) + repeat("What", 4)?upper_case}
结果:
WhatWhatWhat
xxxxxxWHATWHATWHATWHAT
11.操作符优先顺序
后缀 [subvarName] [subStringRange] . (methodParams)
一元 +expr、-expr、!
内建 ?
乘法 *、 / 、%
加法 +、-
关系 <、>、<=、>=(lt、lte、gt、gte)
相等 =、!=
逻辑 &&
逻辑 ||
数字范围 ..
12.一些常用控制语句: 1)if, else, elseif
- <#ifx==1>
- xis1
- <#ify==1>
- andyis1too
- <#else>
- butyisnot
- </#if>
- <#else>
- xisnot1
- <#ify<0>
- andyislessthan0
- </#if>
- </#if>
- <#ifx==1>
- xis1
- <#ify==1>
- andyis1too
- <#else>
- butyisnot
- </#if>
- <#else>
- xisnot1
- <#ify<0>
- andyislessthan0
- </#if>
- </#if>
2)switch, case, default, break
<#switch value>
- <#switchbeing.size>
- <#case"small">
- Thiswillbeprocessedifitissmall
- <#break>
- <#case"medium">
- Thiswillbeprocessedifitismedium
- <#break>
- <#case"large">
- Thiswillbeprocessedifitislarge
- <#break>
- <#default>
- Thiswillbeprocessedifitisneither
- </#switch>
- <#switchbeing.size>
- <#case"small">
- Thiswillbeprocessedifitissmall
- <#break>
- <#case"medium">
- Thiswillbeprocessedifitismedium
- <#break>
- <#case"large">
- Thiswillbeprocessedifitislarge
- <#break>
- <#default>
- Thiswillbeprocessedifitisneither
- </#switch>
3) list, break
- <#listsequenceasitem>
- ${item}
- <#ifitem="xx"><#break></#if>
- </#list>
- <#listsequenceasitem>
- ${item}
- <#ifitem="xx"><#break></#if>
- </#list>
4)include
- <#include"/common/navbar.html"parse=falseencoding="Shift_JIS">
- <#include"/common/navbar.html"parse=falseencoding="Shift_JIS">
5)import
- <#import"/libs/mylib.ftl"asmy>
- <@my.copyrightdate="1999-2002"/>
- <#import"/libs/mylib.ftl"asmy>
- <@my.copyrightdate="1999-2002"/>
Note: that it is possible to automatically do the commonly used imports for all templates, with the "auto imports" setting of Configuration.
6)noparse
- <#noparse>
- <#listanimalsasbeing>
- <tr><td>${being.name}<td>${being.price}Euros
- </#list>
- </#noparse>
- <#noparse>
- <#listanimalsasbeing>
- <tr><td>${being.name}<td>${being.price}Euros
- </#list>
- </#noparse>
7)compress
- <#assignx="moo/n/n">
- (<#compress>
- 12345
- ${moo}
- testonly
- Isaid,testonly
- </#compress>)
- <#assignx="moo/n/n">
- (<#compress>
- 12345
- ${moo}
- testonly
- Isaid,testonly
- </#compress>)
8)escape, noescape
- <#assignx="<test>">
- <#macrom1>
- m1:${x}
- </#macro>
- <#escapexasx?html>
- <#macrom2>m2:${x}</#macro>
- ${x}
- <@m1/>
- </#escape>
- ${x}
- <@m2/>
-
- <#escapexasx?html>
- From:${mailMessage.From}
- Subject:${mailMessage.Subject}
- <#noescape>Message:${mailMessage.htmlFormattedBody}</#noescape>
- ...
- </#escape>
- <#escapexasx?html>
- CustomerName:${customerName}
- Itemstoship:
- <#escapexasitemCodeToNameMap[x]>
- ${itemCode1}
- ${itemCode2}
- ${itemCode3}
- ${itemCode4}
- </#escape>
- </#escape>
- <#assignx="<test>">
- <#macrom1>
- m1:${x}
- </#macro>
- <#escapexasx?html>
- <#macrom2>m2:${x}</#macro>
- ${x}
- <@m1/>
- </#escape>
- ${x}
- <@m2/>
- <#escapexasx?html>
- From:${mailMessage.From}
- Subject:${mailMessage.Subject}
- <#noescape>Message:${mailMessage.htmlFormattedBody}</#noescape>
- ...
- </#escape>
- <#escapexasx?html>
- CustomerName:${customerName}
- Itemstoship:
- <#escapexasitemCodeToNameMap[x]>
- ${itemCode1}
- ${itemCode2}
- ${itemCode3}
- ${itemCode4}
- </#escape>
- </#escape>
9)assign
- <#import"/mylib.ftl"asmy>
- <#assign
- seasons=["winter","spring","summer","autumn"]
- test=test+1
- bgColor="red"inmy
- >
- <#macromyMacro>foo</#macro>
- <#assignx>
- <#list1..3asn>
- ${n}<@myMacro/>
- </#list>
- </#assign>
- Numberofwords:${x?word_list?size}
- ${x}
- <#assignx="Hello${user}!">
- <#import"/mylib.ftl"asmy>
- <#assign
- seasons=["winter","spring","summer","autumn"]
- test=test+1
- bgColor="red"inmy
- >
- <#macromyMacro>foo</#macro>
- <#assignx>
- <#list1..3asn>
- ${n}<@myMacro/>
- </#list>
- </#assign>
- Numberofwords:${x?word_list?size}
- ${x}
- <#assignx="Hello${user}!">
10)global
- <#globalname=value>
- or
- <#globalname1=value1name2=value2...nameN=valueN>
- or
- <#globalname>
- capturethis
- </#global>
- <#globalname=value>
- or
- <#globalname1=value1name2=value2...nameN=valueN>
- or
- <#globalname>
- capturethis
- </#global>
11)local
note:it is similar to assign directive, but it creates or replaces local variables. This works in macro definition bodies only.
- <#localname=value>
- or
- <#localname1=value1name2=value2...nameN=valueN>
- or
- <#localname>
- capturethis
- </#local>
- <#localname=value>
- or
- <#localname1=value1name2=value2...nameN=valueN>
- or
- <#localname>
- capturethis
- </#local>
12)setting
note:The supported settings are:locale,number_format,boolean_format,
date_format, time_format, datetime_format,time_zone,url_escaping_charset,classic_compatible
- ${1.2}
- <#settinglocale="en_US">
- ${1.2}
- ${1.2}
- <#settinglocale="en_US">
- ${1.2}
13) (<@...>)
- <@myRepeatMacrocount=4;x,last>
- ${x}.Something...<#iflast>Thiswasthelast!</#if>
- </@myRepeatMacro>
- <@myRepeatMacrocount=4;x,last>
- ${x}.Something...<#iflast>Thiswasthelast!</#if>
- </@myRepeatMacro>
14)macro, nested, return
- <#macroimgsrcextra...>
- <imgsrc="/context${src?html}"
- <#listextra?keysasattr>
- ${attr}="${extra[attr]?html}"
- </#list>
- >
- </#macro>
- <@imgsrc="/images/test.png"width=100height=50alt="Test"/>
- <#macrorepeatcount>
- <#list1..countasx>
- <#nestedx,x/2,x==count>
- </#list>
- </#macro>
- <@repeatcount=4;c,halfc,last>
- ${c}.${halfc}<#iflast>Last!</#if>
- </@repeat>
- <#macrotest>
- Testtext
- <#return>
- Willnotbeprinted.
- </#macro>
- <@test/>
- <#macroimgsrcextra...>
- <imgsrc="/context${src?html}"
- <#listextra?keysasattr>
- ${attr}="${extra[attr]?html}"
- </#list>
- >
- </#macro>
- <@imgsrc="/images/test.png"width=100height=50alt="Test"/>
- <#macrorepeatcount>
- <#list1..countasx>
- <#nestedx,x/2,x==count>
- </#list>
- </#macro>
- <@repeatcount=4;c,halfc,last>
- ${c}.${halfc}<#iflast>Last!</#if>
- </@repeat>
- <#macrotest>
- Testtext
- <#return>
- Willnotbeprinted.
- </#macro>
- <@test/>
15)function, return
- <#functionavgnums...>
- <#localsum=0>
- <#listnumsasnum>
- <#localsum=sum+num>
- </#list>
- <#ifnums?size!=0>
- <#returnsum/nums?size>
- </#if>
- </#function>
- ${avg(10,20)}
- ${avg(10,20,30,40)}
- ${avg()!"N/A"}
- <#functionavgnums...>
- <#localsum=0>
- <#listnumsasnum>
- <#localsum=sum+num>
- </#list>
- <#ifnums?size!=0>
- <#returnsum/nums?size>
- </#if>
- </#function>
- ${avg(10,20)}
- ${avg(10,20,30,40)}
- ${avg()!"N/A"}
16).flush
17)stop
18)ftl
19)t, lt, rt
20)nt
21)attempt, recover
- Primarycontent
- <#attempt>
- Optionalcontent:${thisMayFails}
- <#recover>
- Ops!Theoptionalcontentisnotavailable.
- </#attempt>
- Primarycontentcontinued
- Primarycontent
- <#attempt>
- Optionalcontent:${thisMayFails}
- <#recover>
- Ops!Theoptionalcontentisnotavailable.
- </#attempt>
- Primarycontentcontinued
22)visit, recurse, fallback
三. Interpolation:由${...}或#{...}两种类型,输出计算值,可以自定义输出的格式
1)string的操作: substring
cap_first
uncap_first
capitalize
chop_linebreak
date, time, datetime
ends_with
html
groups
index_of
j_string
js_string
last_index_of
length
lower_case
left_pad
right_pad
contains
matches
number
replace
rtf
url
split
starts_with
string (when used with a string value) trim
upper_case
word_list
xml
2)numbers的操作: c
string (when used with a numerical value)
round, floor, ceiling
3)dates的操作: string (when used with a date value)
date, time, datetime
4)booleans的操作: string (when used with a boolean value)
5)sequences的操作: first
last
seq_contains
seq_index_of
seq_last_index_of
reverse
size
sort
sort_by
chunk
6)hashes的操作: keys
values
7)nodes 的操作: children
parent
root
ancestors
node_name
node_type
node_namespace
四.) 注释:<#--和-->
下面是一个常用的模板例子:
例一:
- <p>Wehavetheseanimals:
- <tableborder=1>
- <tr><th>Name<th>Price
- <#listanimalsasbeing>
- <tr>
- <td>
- <#ifbeing.size="large"><b></#if>
- ${being.name}
- <#ifbeing.size="large"></b></#if>
- <td>${being.price}Euros
- </#list>
- </table>
- <#include"/copyright_footer.html">
- <p>Wehavetheseanimals:
- <tableborder=1>
- <tr><th>Name<th>Price
- <#listanimalsasbeing>
- <tr>
- <td>
- <#ifbeing.size="large"><b></#if>
- ${being.name}
- <#ifbeing.size="large"></b></#if>
- <td>${being.price}Euros
- </#list>
- </table>
- <#include"/copyright_footer.html">
注意点:
1.) FreeMarker是区分大小写的;
2.) FTL标记不能位于另一个FTL标记内部,例如:<#if <#include 'foo'>='bar'>...</if>;
3.) ${…}只能在文本中使用;
4.) 多余的空白字符会在模板输出时去除;
5.) 如果使用的指令不存在,会产生一个错误消息。
例子2。
- <%@tagliburi="/WEB-INF/fmtag.tld"prefix="fm"%>
- <jsp:useBeanid="mybean"class="<SPANclass=hilite1>freemarker</SPAN>.examples.jsp.SimpleBean"/>
- <jsp:useBeanid="mybeanreq"class="<SPANclass=hilite1>freemarker</SPAN>.examples.jsp.SimpleBean"scope="request"/>
- <fm:template>
- <html>
- <head>
- <title><SPANclass=hilite1>FreeMarker</SPAN>JSPExample</title>
- </head>
- <body>
- <h1><SPANclass=hilite1>FreeMarker</SPAN>JSPexample</h1>
- <hr>
- <p>
- ThispageisaJSPpage,yetmostofitscontentsisgeneratedusing
- a<SPANclass=hilite1>FreeMarker</SPAN>template.Thebelowlinesaretheoutputofcalling
- propertiesonaJSP-declaredbeanfromthe<SPANclass=hilite1>FreeMarker</SPAN>template:
- </p>
-
- <#assignmybean=page.mybean>
- <#assignmybeanreq=request.mybeanreq>
-
- <p>page:${mybean.string}
- <#listmybean.arrayasitem>
- <br>${item}
- </#list>
- <br>request:${mybeanreq.string}
-
- <p><b>Note:</b>Startingfrom<SPANclass=hilite1>FreeMarker</SPAN>2.2youcanusecustomJSPtagsin
- <SPANclass=hilite1>FreeMarker</SPAN>templates.IfyouwanttomigratefromJSPtoFTL(i.e.<SPANclass=hilite1>FreeMarker</SPAN>templates),
- thenthat'sprobablyabetteroptionthanembeddingFTLintoJSPpages.
- </body>
- </html>
- </fm:template>
- <%@tagliburi="/WEB-INF/fmtag.tld"prefix="fm"%>
- <jsp:useBeanid="mybean"class="<spanclass="hilite1">freemarker</span>.examples.jsp.SimpleBean"/>
- <jsp:useBeanid="mybeanreq"class="<spanclass="hilite1">freemarker</span>.examples.jsp.SimpleBean"scope="request"/>
- <fm:template>
- <html>
- <head>
- <title><spanclass="hilite1">FreeMarker</span>JSPExample</title>
- </head>
- <body>
- <h1><spanclass="hilite1">FreeMarker</span>JSPexample</h1>
- <hr>
- <p>
- ThispageisaJSPpage,yetmostofitscontentsisgeneratedusing
- a<spanclass="hilite1">FreeMarker</span>template.Thebelowlinesaretheoutputofcalling
- propertiesonaJSP-declaredbeanfromthe<spanclass="hilite1">FreeMarker</span>template:
- </p>
- <#assignmybean=page.mybean>
- <#assignmybeanreq=request.mybeanreq>
- <p>page:${mybean.string}
- <#listmybean.arrayasitem>
- <br>${item}
- </#list>
- <br>request:${mybeanreq.string}
- <p><b>Note:</b>Startingfrom<spanclass="hilite1">FreeMarker</span>2.2youcanusecustomJSPtagsin
- <spanclass="hilite1">FreeMarker</span>templates.IfyouwanttomigratefromJSPtoFTL(i.e.<spanclass="hilite1">FreeMarker</span>templates),
- thenthat'sprobablyabetteroptionthanembeddingFTLintoJSPpages.
- </body>
- </html>
- </fm:template>
fmtag.tld文件:
- <?xmlversion="1.0"encoding="ISO-8859-1"?>
- <!DOCTYPEtaglib
- PUBLIC"-//SunMicrosystems,Inc.//DTDJSPTagLibrary1.1//EN"
- "http://java.sun.com/j2ee/dtds/web-jsptaglib_1_1.dtd">
- <taglib>
- <tlibversion>2.0</tlibversion>
- <jspversion>1.1</jspversion>
- <shortname><SPANclass=hilite1>FreeMarker</SPAN>JSPSupport</shortname>
- <tag>
- <name>template</name>
- <tagclass><SPANclass=hilite1>freemarker</SPAN>.ext.jsp.<SPANclass=hilite1>Freemarker</SPAN>Tag</tagclass>
- <bodycontent>tagdependent</bodycontent>
- <info>Allowsevaluationof<SPANclass=hilite1>FreeMarker</SPAN>templatesinsideJSP</info>
- <attribute>
- <name>caching</name>
- <required>false</required>
- </attribute>
- </tag>
- </taglib>
- <?xmlversion="1.0"encoding="ISO-8859-1"?>
- <!DOCTYPEtaglib
- PUBLIC"-//SunMicrosystems,Inc.//DTDJSPTagLibrary1.1//EN"
- "http://java.sun.com/j2ee/dtds/web-jsptaglib_1_1.dtd">
- <taglib>
- <tlibversion>2.0</tlibversion>
- <jspversion>1.1</jspversion>
- <shortname><spanclass="hilite1">FreeMarker</span>JSPSupport</shortname>
- <tag>
- <name>template</name>
- <tagclass><spanclass="hilite1">freemarker</span>.ext.jsp.<spanclass="hilite1">Freemarker</span>Tag</tagclass>
- <bodycontent>tagdependent</bodycontent>
- <info>Allowsevaluationof<spanclass="hilite1">FreeMarker</span>templatesinsideJSP</info>
- <attribute>
- <name>caching</name>
- <required>false</required>
- </attribute>
- </tag>
- </taglib>
例子3:
inedex.ftl 代码:
- <#import"/lib/common.ftl"ascom>
- <#escapexasx?html>
- <@com.pagetitle="Index">
- <ahref="form.do">Addnewmessage</a>|<ahref="help.html">Help</a>
- <#ifguestbook?size=0>
- <p>Nomessages.
- <#else>
- <p>Themessagesare:
- <tableborder=0cellspacing=2cellpadding=2width="100%">
- <tralign=centervalign=top>
- <thbgcolor="#C0C0C0">Name
- <thbgcolor="#C0C0C0">Message
- <#listguestbookase>
- <tralign=leftvalign=top>
- <tdbgcolor="#E0E0E0">${e.name}<#ife.email?length!=0>(<ahref="mailto:${e.email}">${e.email}</a>)</#if>
- <tdbgcolor="#E0E0E0">${e.message}
- </#list>
- </table>
- </#if>
- </@com.page>
- </#escape>
- <#import"/lib/common.ftl"ascom>
- <#escapexasx?html>
- <@com.pagetitle="Index">
- <ahref="form.do">Addnewmessage</a>|<ahref="help.html">Help</a>
- <#ifguestbook?size=0>
- <p>Nomessages.
- <#else>
- <p>Themessagesare:
- <tableborder=0cellspacing=2cellpadding=2width="100%">
- <tralign=centervalign=top>
- <thbgcolor="#C0C0C0">Name
- <thbgcolor="#C0C0C0">Message
- <#listguestbookase>
- <tralign=leftvalign=top>
- <tdbgcolor="#E0E0E0">${e.name}<#ife.email?length!=0>(<ahref="mailto:${e.email}">${e.email}</a>)</#if>
- <tdbgcolor="#E0E0E0">${e.message}
- </#list>
- </table>
- </#if>
- </@com.page>
- </#escape>
form.ftl代码
- <#import"/lib/common.ftl"ascom>
- <#globalhtml=JspTaglibs["/WEB-INF/struts-html.tld"]>
- <#escapexasx?html>
- <@com.pagetitle="AddEntry">
- <@html.errors/>
-
- <@html.formaction="/add">
- <p>Yourname:<br>
- <@html.textproperty="name"size="60"/>
- <p>Youre-mail(optional):<br>
- <@html.textproperty="email"size="60"/>
- <p>Message:<br>
- <@html.textareaproperty="message"rows="3"cols="60"/>
- <p><@html.submitvalue="Submit"/>
- </@html.form>
-
- <p><ahref="index.do">Backtotheindexpage</a>
- </@com.page>
- </#escape>
- <#import"/lib/common.ftl"ascom>
- <#globalhtml=JspTaglibs["/WEB-INF/struts-html.tld"]>
- <#escapexasx?html>
- <@com.pagetitle="AddEntry">
- <@html.errors/>
- <@html.formaction="/add">
- <p>Yourname:<br>
- <@html.textproperty="name"size="60"/>
- <p>Youre-mail(optional):<br>
- <@html.textproperty="email"size="60"/>
- <p>Message:<br>
- <@html.textareaproperty="message"rows="3"cols="60"/>
- <p><@html.submitvalue="Submit"/>
- </@html.form>
- <p><ahref="index.do">Backtotheindexpage</a>
- </@com.page>
- </#escape>
add.ftl代码内容
- <#import"/lib/common.ftl"ascom>
- <#escapexasx?html>
- <@com.pagetitle="Entryadded">
- <p>Youhaveaddedthefollowingentrytotheguestbook:
- <p><b>Name:</b>${guestbookEntry.name}
- <#ifguestbookEntry.email?length!=0>
- <p><b>Email:</b>${guestbookEntry.email}
- </#if>
- <p><b>Message:</b>${guestbookEntry.message}
- <p><ahref="index.do">Backtotheindexpage...</a>
- </@com.page>
- </#escape>
- <#import"/lib/common.ftl"ascom>
- <#escapexasx?html>
- <@com.pagetitle="Entryadded">
- <p>Youhaveaddedthefollowingentrytotheguestbook:
- <p><b>Name:</b>${guestbookEntry.name}
- <#ifguestbookEntry.email?length!=0>
- <p><b>Email:</b>${guestbookEntry.email}
- </#if>
- <p><b>Message:</b>${guestbookEntry.message}
- <p><ahref="index.do">Backtotheindexpage...</a>
- </@com.page>
- </#escape>
common.ftl的 代码
- <#macropagetitle>
- <html>
- <head>
- <title><SPANclass=hilite1>FreeMarker</SPAN>StrutsExample-${title?html}</title>
- <metahttp-equiv="Content-type"content="text/html;charset=ISO-8859-1">
- </head>
- <body>
- <h1>${title?html}</h1>
- <hr>
- <#nested>
- <hr>
- <tableborder="0"cellspacing=0cellpadding=0width="100%">
- <trvalign="middle">
- <tdalign="left">
- <i><SPANclass=hilite1>FreeMarker</SPAN>StrutsExample</i>
- <tdalign="right">
- <ahref="http://<SPANclass=hilite1>freemarker</SPAN>.org"><imgsrc="poweredby_ffffff.png"border=0></a>
- </table>
- </body>
- </html>
- </#macro>
- <#macropagetitle>
- <html>
- <head>
- <title><spanclass="hilite1">FreeMarker</span>StrutsExample-${title?html}</title>
- <metahttp-equiv="Content-type"content="text/html;charset=ISO-8859-1">
- </head>
- <body>
- <h1>${title?html}</h1>
- <hr>
- <#nested>
- <hr>
- <tableborder="0"cellspacing=0cellpadding=0width="100%">
- <trvalign="middle">
- <tdalign="left">
- <i><spanclass="hilite1">FreeMarker</span>StrutsExample</i>
- <tdalign="right">
- <ahref="http://<spanclass="hilite1">freemarker</span>.org"><imgsrc="poweredby_ffffff.png"border=0></a>
- </table>
- </body>
- </html>
- </#macro>
|
|