继续潜水

导航

 

在web中添加一段代码

 <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>textml</param-value>
    </init-param>
    <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>locale</param-name>
      <param-value>zh_CN</param-value>
    </init-param>
    <init-param>
      <param-name>default_encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
      <param-name>boolean_format</param-name>
      <param-value>true,false</param-value>
    </init-param>
      <init-param>
      <param-name>number_format</param-name>
      <param-value>0.##########</param-value>
    </init-param>
  </servlet>

  <!-- freemarker-->
  <servlet-mapping>
        <servlet-name>freemarker</servlet-name>
        <url-pattern>*.html</url-pattern>
  </servlet-mapping>

 

如果在使用include是不能读取引用文件内容,需在web.xml吧<url-pattern>*.html</url-pattern>改成ftl

如果页面乱码ftl首行加

<#ftl attributes={"content_type":"text/html; charset=utf-8"} />

 

书上所述(尚未验证)

<servlet>
<servlet-name>freemarker</servlet-name>
<servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class>
<!--FreemarkerServlet 设置: -->
<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; charset=UTF-8</param-value> <!--强制使用UTF-8作为输出编码格式! --> </init-param> <!--FreeMarker设置: -->
<init-param><param-name>template_update_delay</param-name> <param-value>0</param-value> <!--0 只对开发使用! 否则使用大一点的值. --></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>

 

posted on 2015-09-22 15:51  继续潜水  阅读(914)  评论(0编辑  收藏  举报