Json异常-AJAX-406解析异常(spring-mvc中)

2017-08-14  本文已影响0人  TeaR0502

贴上异常

Failed to load resource: the server responded with a status of 406 ()

下面是我的WEB.XML文档

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">
    <display-name>springMVC01</display-name>
    <servlet>
        <servlet-name>SpringMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- 局部变量,可向Listener,Filter,Servlet里面传参 -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>SpringMVC</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
    
</web-app>

一开始百思不得其解,后来弄明白了.
看我配置中
因为做伪装处理所以把后缀名后改成了html

<url-pattern>*.html</url-pattern>

导致了spring mvc会默认采用text/html来编码,因此出现Json格式出现异常

总结:只要把html改成其他的就可以正常获取Json字符串了

<url-pattern>*.json</url-pattern>
上一篇 下一篇

猜你喜欢

热点阅读