Freemarker中文乱码

来源:6-1 SpringMVC整合Freemarker

guo_x

2020-02-28 13:26:31

Freemarker已经在配置文件中配置了默认字符集,但是在页面显示还是中文乱码

http://img.mukewang.com/climg/5e58a4780924668e11430533.jpg

http://img.mukewang.com/climg/5e58a478092fc15810910336.jpg

http://img.mukewang.com/climg/5e58a4790906269316390938.jpg


写回答

3回答

好帮手慕柯南

2020-03-01

同学你好!

  1. 在xml中配置的编码,是告诉浏览器以utf-8来解析页面

  2. “??”这种形式的乱码,通常是后台但返回的数据不是uft-8导致的。是相应乱码。

    你添加一下以下配置就可以

    http://img.mukewang.com/climg/5e5b19b509073cf109650415.jpg

    具体代码:

<mvc:annotation-driven >
    <mvc:message-converters>
        <bean class="org.springframework.http.converter.StringHttpMessageConverter">
            <property name="supportedMediaTypes">
                <list>
                    <!-- response.setContentType("text/html;charset=utf-8") -->
                    <value>text/plain;charset=utf-8</value>
                    <value>text/html;charset=utf-8</value>
                </list>
            </property>
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>
<!-- 将图片/JS/CSS等静态资源排除在外,可提高执行效率 -->
<mvc:default-servlet-handler/>

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

0

guo_x

提问者

2020-02-29

http://img.mukewang.com/climg/5e5a7411090e2c9813840490.jpg

http://img.mukewang.com/climg/5e5a741109dc444d18871212.jpg


0

好帮手慕阿满

2020-02-28

同学你好,建议同学在freemarker模板头部加上如下代码再试试。

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

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

0
huo_x
h 还是乱码,我按F12查看headers中 Content-Type: text/html; character=utf-8;charset=ISO-8859-1 ; 我命名是设置过charset = utf-8,的,见附件 meta和 heardrs
h020-02-29
共1条回复

0 学习 · 8263 问题

查看课程