在确定模板文件代码无误的情况下,导致报错的原因大概有以下原因:

模板文件编码改变了(比如eclipse中的项目部署到tomcat下,而忘记设置tomcat编码就会导致读取模板文件编码不正确,导致程序解析报错)

解决方法:

Configuration cfg = new Configuration();
cfg.setDefaultEncoding("UTF-8"); Template template = cfg.getTemplate(templateFileName);
template.setEncoding("UTF-8");

创建freemarker配置实例时设置好编码,获取模板文件时设置编码,编码要一致,这样可以解决编码的问题。

推荐部署项目时设置tomcat编码为utf-8:

修改server.xml文件

<Connector
port="8080"
maxThreads="150"
minSpareThreads="25" maxSpareThreads="75"
enableLookups="false"
redirectPort="8443"
acceptCount="100"
debug="0"
connectionTimeout="20000"
disableUploadTimeout="true"
URIEncoding="UTF-8"
/> URIEncoding用于解码URL的字符编码,没有指定默认值为ISO-8859-1
关于tomcat详细配置参考:http://blog.csdn.net/cicada688/article/details/14451541

freemarker解析模板报错问题的更多相关文章

  1. FreeMarker / S2SH 各种报错解决方案

    1. org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of ...

  2. 【spring boot】spring boot 前台GET请求,传递时间类型的字符串,后台无法解析,报错:Failed to convert from type [java.lang.String] to type [java.util.Date]

    spring boot 前台GET请求,传递时间类型的字符串,后台无法解析,报错:Failed to convert from type [java.lang.String] to type [jav ...

  3. golang解析json报错:invalid character '\x00' after top-level value

    golang解析json报错:invalid character '\x00' after top-level value 手动复制字符串:{"files":["c:/t ...

  4. DOM解析XML报错:Content is not allowed in prolog

    报错内容为: Content is not allowed in prolog. Nested exception: Content is not allowed in prolog. 网上所述总结来 ...

  5. 当html中存在url中如: onclick="toView('参数1')", 参数1是特别字符,如&asop;&quot;' "等时,浏览器解析时会报错。解决方法如文中描述

    解决方案: 自定义标签将字符串转换成unicode编码后输出显示到页面即可 解析原理:解析顺序html  ---url ----javascript---url,由于unicode编码在htm解析阶段 ...

  6. RobotFramework中解析中文报错UnicodeDecodeError

    在RobotFramework中解析一段包含中文的字符串时遇到下面的报错: FAIL : UnicodeDecodeError: 'ascii' codec can't decode byte 0xe ...

  7. freemarker自定义标签报错(四)

    freemarker自定义标签 1.错误描述 六月 05, 2014 11:31:35 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严 ...

  8. dom4j解析xml报错:Nested exception: org.xml.sax.SAXParseException: White space is required between the processing instruction target and data.

    采用dom4j方式解析string类型的xml xml:        String string="<?xmlversion=\"1.0\" encoding=\ ...

  9. 利用json模块解析dict报错找不到attribute 'dumps'[python2.7]

    [背景] 环境: RHEL 7.3 版本: python2.7 [错误情况] 写了一个简单的python脚本 将dict转换为json 脚本如下: #!/usr/bin/python #-*- cod ...

随机推荐

  1. PCL Nodelets 和 3D 点云---36

    原创博客:转载请标明出处:http://www.cnblogs.com/zxouxuewei/ 1.首先确保你的kinect驱动或者uvc相机驱动能正常启动,如果你没有安装kinect深度相机驱动,请 ...

  2. openni和骨架追踪 rviz查看---34

    原创博客:转载请标明出处:http://www.cnblogs.com/zxouxuewei/ 1.安装深度相机的NITE. 首先下载NITE-Bin-Dev-Linux-x64-v1.5.2.23, ...

  3. 4-1 yum源文件

    1.Yum源文件 <1>在Linux中,有这样一个目录 /etc/yum.repos.d/,里面有默认4个yum源文件, 其中Base是基本yum源文件,它是默认生效的 其他的几个默认都是 ...

  4. hihoCoder #1078 : 线段树的区间修改

    题目大意及分析: 线段树成段更新裸题. 代码如下: # include<iostream> # include<cstdio> # include<cstring> ...

  5. 越狱Season 1-Episode 15: By the Skin and the Teeth

    Season 1, Episode 15: By the Skin and the Teeth -Pope: doctor...you can leave. 医生你得离开 -Burrows: It's ...

  6. 越狱Season 1-Episode 13: End of the Tunnel

    Season 1, Episode 13: End of the Tunnel -Fernando: The name is John Abruzzi. 名字是John Abruzzi A b r u ...

  7. makefile基础实例讲解 分类: C/C++ 2015-03-16 10:11 66人阅读 评论(0) 收藏

    一.makefile简介 定义:makefile定义了软件开发过程中,项目工程编译链.接接的方法和规则. 产生:由IDE自动生成或者开发者手动书写. 作用:Unix(MAC OS.Solars)和Li ...

  8. Codeforces Round #339 Div.2 B - Gena's Code

    It's the year 4527 and the tanks game that we all know and love still exists. There also exists Grea ...

  9. 论文笔记之:Deep Reinforcement Learning with Double Q-learning

    Deep Reinforcement Learning with Double Q-learning Google DeepMind Abstract 主流的 Q-learning 算法过高的估计在特 ...

  10. 论文笔记之:Playing Atari with Deep Reinforcement Learning

    Playing Atari with Deep Reinforcement Learning <Computer Science>, 2013 Abstract: 本文提出了一种深度学习方 ...