Spring MVC 前后台传递json格式数据 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

若使用默认的json转换器,则需要如下包;

<mvc:annotation-driven />

 

报错如下:

Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

   解决方案:

   引入如下包:

   

   

 

    问题既解决。

 

 

    若使用外部的其他json转换,则需要配置相关的转换器

     如:

     

复制代码
<mvc:annotation-driven>
        <mvc:message-converters register-defaults="false">
            <bean class="org.springframework.http.converter.StringHttpMessageConverter" />
            <bean
                class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" />
            <bean
                class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
            <bean
                class="org.springframework.http.converter.BufferedImageHttpMessageConverter" />
            <!-- 配置fastjson中实现httpMessageConverter接口的转换器 -->
            <bean id="fastJsonHttpMessageConverter"
                class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter" >
            <!-- 加入支持的媒体类型:返回contentType -->    
            <property name="supportedMediaTypes">
                <list>
                    <!-- 这里顺序不能写反,一定先写text/html,不然IE会出现下载提示 -->
                    <value>text/html;charset:UTF-8</value>
                    <value>application/json;charset:UTF-8</value>
                </list>
            </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>
    <mvc:default-servlet-handler />
复制代码

 

posted @ 2019-07-16 11:14  不良徐某  阅读(1038)  评论(0编辑  收藏  举报