sping3 ajax 乱码

来源:互联网 发布:iis ip地址和域名限制 编辑:程序博客网 时间:2024/05/17 03:50

一、如果你使用的是spring3.0

 

1    配置如下:

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
        <property name="messageConverters">
            <list>
                <bean class = "org.springframework.http.converter.StringHttpMessageConverter">
                    <property name="writeAcceptCharset" value="false"></property>
                    <property name = "supportedMediaTypes">
                    <list>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                    </property>
                </bean>
            </list>
        </property>
    </bean>

 

 注意:需要放在 <mvc:annotation-driven /> 之前,不然配置会被覆盖。

 

2, @RequestMapping 的 produces在3.0是不支持的。

 

 

二、如果使用的spring3.1包

 

1   配置如下:

<mvc:annotation-driven >
        <mvc:message-converters register-defaults="false">
        <bean class="org.springframework.http.converter.StringHttpMessageConverter">
            <property name="supportedMediaTypes" value = "text/plain;charset=UTF-8" />
        </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

 

  注意:你的spring配置文件命名空间必须使用3.1才不会报错,例如:

   http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd

 

 2,或者在controller中的requestmapping中配置

@RequestMapping(value="/test", produces = "application/json; charset=utf-8")