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 />

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM