Web项目,异步获取,数据展示乱码的问题笔记

参与的一个后台管理系统的开发,涉及到SpringMVC,Maven,Gson,Velocity等相关技术

问题:Ajax请求,转到服务器,进行逻辑判断后,传回结果,显示????

检查:web.xml中配置了包含字符过滤器,velocity头信息包含UTF-8字符集设置,velocity配置文件表明字符集设置UTF-8,spring配置文件中对于velocity页面的部分配置。

<filter>
    <filter-name>CharacterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>  
        <param-name>forceEncoding</param-name>  
        <param-value>true</param-value>  
    </init-param>  
</filter>
<filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<meta charset="utf-8">
input.encoding=UTF-8
output.encoding=UTF-8
<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"> 
	<property name="suffix" value=".vm" /> 
	<property name="exposeRequestAttributes" value="true"/> 
	<property name="exposeSessionAttributes" value="true" /> 
	<property name="contentType" value="text/html;charset=UTF-8" />
	<!-- 页面使用工具类配置 -->
	<property name="toolboxConfigLocation" value="/WEB-INF/toolbox.xml"/>
</bean>
依旧存在该问题,

解决方案如下:在spring中增加配置

    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="urlDecode" value="true"/>
        <property name="messageConverters">
            <list>
                <bean class=" org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
                <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
                <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
                <bean class="org.springframework.http.converter.FormHttpMessageConverter"/>
                <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
            </list>
        </property>
    </bean>

初步判断问题原因在
org.springframework.http.converter.StringHttpMessageConverter
中的默认字符集是ISO-8859-1,造成的字符转换问题,问题虽然解决,但还有很多东西不是很理解,继续加油吧


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值