【实用小技巧】freemarker模板中文乱码问题解决

freemarker简单模板如下:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <title>中文</title>
    </head>
    <body>
        <h1>${name}</h1>
        <h2>中文测试</h2>
    </body>
</html>

方案如下:

  • 设置模板文件本身的属性:右键文件,选择properties,看text file encoding 选择UTF-8编码。
  • 在头部加标签:<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  • request、response 设置编码格式为UTF-8。
原文地址:https://www.cnblogs.com/oldwei/p/9098516.html