quhaojian
2015-11-18 07:47
采纳率: 50%
浏览 2.9k
已采纳

spring mvc json返回中文乱码 配置后依然不好使

  <context:annotation-config />
     <context:component-scan base-package="may.web.action"></context:component-scan>


      <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
                <property name="messageConverters">
                    <list>
                         <bean class = "org.springframework.http.converter.StringHttpMessageConverter">    
                  <property name = "supportedMediaTypes">   
                        <list>    
                          <value>text/plain;charset=UTF-8</value>
                          <value>application/json;charset=UTF-8</value>    
                      </list>    
                  </property>  
                     </bean> 
                     <bean  class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
                  </list>
            </property>
            <property name="webBindingInitializer">  
                <bean class="may.filter.MyBindingInitializer"/>  
            </property>
         </bean> 

     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
        <property name="viewClass"
                    value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/jsp/"></property>  
        <property name="suffix" value=".jsp"></property>  
        </bean>
    <mvc:annotation-driven/>


      </beans>
        xml已经配置了  但是还是中文乱码  还是text/plain:charset=ISO8859-1,自己弄了一下午 但还是不好使 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • CS568591377 2015-11-18 08:30
    已采纳
        <!-- mvc 返回乱码处理 -->
        <mvc:annotation-driven>
            <mvc:message-converters register-defaults="true">
                <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                    <property name="supportedMediaTypes" value="text/plain;charset=UTF-8" />
                </bean>
            </mvc:message-converters>
        </mvc:annotation-driven>
    
    点赞 评论
  • CS568591377 2015-11-18 08:27
    点赞 评论
  • Evankaka 2015-11-18 14:10

    这个我搞过,看看这里吧http://blog.csdn.net/evankaka/article/details/49452201
    spring-mvc.xml的配置

    点赞 评论