问题描述
- 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,自己弄了一下午 但还是不好使
解决方案
<!-- 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>
解决方案二:
spring mvc json返回中文乱码
解决方案三:
把你的mvc:annotation-driven/配置改成下面的试试看:
mvc:annotation-driven
/mvc:message-converters
/mvc:annotation-driven
解决方案四:
这个我搞过,看看这里吧http://blog.csdn.net/evankaka/article/details/49452201
spring-mvc.xml的配置
时间: 2024-10-31 09:05:20