貼上異常
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里面?zhèn)鲄?-->
<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來編碼,因此出現(xiàn)Json格式出現(xiàn)異常
總結:只要把html改成其他的就可以正常獲取Json字符串了
<url-pattern>*.json</url-pattern>