freemark生成静态网页乱码问题

时间:2022-06-20 15:05:24

输出流问题:修改Writer如下:

OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(dir), "UTF-8");
PrintWriter printWriter = new PrintWriter(writer);

模板页面问题,在模板页面中添加:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">  

freemark没有设置编码格式,修改配置文件:

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

乱码解决。