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

模板文件编码改变了(比如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. 11g新特性与12c新特性

    1. 11g新特性概图 管理新特性> 开发新特性> 2. 12c 新特性概图

  2. rac 11g_生产库日志组损坏处理

    原创作品,出自 "深蓝的blog" 博客,转载时请务必注明出处,否则有权追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlong/ar ...

  3. web前端面试2

    百度另外一部门面试 1.前端html5新特性 2.数组常用函数 3.前后台json树形结构遍历,对算法的了解 4.css3背景属性设置为适合匹配模块的属性是什么 5.jquery插件的写法 6.研究过 ...

  4. Deferred和Promise之间有什么区别呢?

    一个promise就是一个由异步函数返回的对象. deferred对象就是jQuery的回调函数解决方案. 总结 jQuery 的ajax 就是返回一个promise 对象,里面含有done(), f ...

  5. apache commons vfs 文件夹监控

    package test.vfs; import java.io.File; import org.apache.commons.logging.Log; import org.apache.comm ...

  6. 200多个js技巧代码

    1.文本框焦点问题 onBlur:当失去输入焦点后产生该事件 onFocus:当输入获得焦点后,产生该文件 Onchange:当文字值改变时,产生该事件 Onselect:当文字加亮后,产生该文件 & ...

  7. mysql 远程访问授权

    给mysql改了密码了,程序就不让登录了: mysql 网外链接 Access denied for user 这不能忍啊!咋办?授权呗! 命令行: GRANT ALL PRIVILEGES ON * ...

  8. VMware 虚拟机Red Hat 5.9 交换区及硬盘空间调整

    首先要通过VMware设置简单实现内存扩大.但是系统中的/swap应该如何设置呢? 1. 创建swap 文件 使用如下命令: #dd if=/dev/zero of=/swap/swapfile bs ...

  9. nginx ssi 配置小细节(一)

    最近工作需要使用nginx的ssi (server side include)技术,在这里,将使用中的一点心得分享一下,也是一种备忘! 首先,nginx的ssi启用很简单,就只有三个最基本的指令: s ...

  10. ORACLE的表被 另一个用户锁定,如何解除..

    SELECT object_name, machine, s.sid, s.serial# FROM gv$locked_object l, dba_objects o, gv$session s W ...