1 FreeMarker 不会语法模板中使用JSP标签 <servlet> <servlet-name>JspSupportServlet</servlet-name> <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <#assign c =JspTaglibs["/WEB-INF/tld/c.tld"] > 使用方法 <@c.import url="http://127.0.0.1:8080/menu.do"/>
2 .取Application范围的对象 <#if Application.myApplicationAttribute?exists> ${Application.myApplicationAttribute} </#if>
取session范围的对象 <#if Session.mySessionAttribute?exists> ${Session.mySessionAttribute} </#if>
取request范围的对象 <#if Request.myRequestAttribute?exists> ${Request.myRequestAttribute} </#if>
取request parameter范围的对象 <#if Parameters.myParameter?exists> ${Parameters.myParameter} </#if>
取context parameter范围的对象 ${stack.findValue('#myContextParam')}
web.xml
<servlet>
<servlet-name>freemarker</servlet-name>
<servlet-class> freemarker.ext.servlet.FreemarkerServlet </servlet-class> <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>
<init-param>
<param-name>template_update_delay</param-name> <param-value>0</param-value>
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>GBK</param-value>
</init-param>
<init-param>
<param-name>locale</param-name>
<param-value>en_ZH</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>action</servlet-name>
<url-pattern>*.do</url-pattern> </servlet-mapping>
<servlet-mapping> <servlet-name>freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern> </servlet-mapping> <session-config>
<session-timeout>10</session-timeout> </session-config>
<#include "../common/style.jsp">
<#list templist as vo>
${vo.vcity} </#list >
<#macro greet person color> //定义宏 <font size="+2" color="${color}">Hello ${person}!</font> </#macro>
<#local y = "test">
<#assign user = "Joe Hider"> 全局变量