claudioivp claudioivp - 4 years ago 256
Java Question

Freemarker utf-8 encoding problems on

I'm having problems with inside pages. It simply are recognizing pages as iso, but I want utf-8, I'm declaring it as default charset. I tried some modifications on freemarker configuration, but they are not having effect.


<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/pages/"/>


<#macro page>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cemitério - Prefeitura Municipal de Maringá</title>



<#import "templates/template.html" as t/>


<#if erroLogin??>
<form action="entrar" method="post">
<input type="text" name="usuario" />
<br />
<input type="text" name="senha" />
<br />
<input type="submit" name="submit" />



enter image description here

Answer Source

Since the accents were all right in the inserted variables, yet the accents entered directly into the templates weren't, and the browser seems to know that the page uses UTF-8 (that you can check in the page information dialog of the browser), either:

  • The template file was saved with the wrong encoding. In Eclipse, you should go to Window -> Preferences -> Workspace, and set text file encoding to UTF-8. This is a global setting, but by default Eclipse uses the platform default, which doesn't make sense in 99% of the projects. You can also set this on project level under Project -> Properties -> Resource.

  • FreeMarker has used wrong charset to decode the template files, as it also uses the platform default by default. So you should set the default_encoding setting to UTF-8. You can also force the encoding in the template with <#ftl encoding='UTF-8'>.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download