SpringMVC中,如果前端请求,服务端响应406错误。可能是服务端没有加入Jackson的Jar包,并且使用了@ResponseBody返回数据,就会报406的错误。
还有一种可能是:web.xml中配置的拦截请求是*.html,请求返回的却是一个Json对象。SpringMVC中不允许请求*.html但却返回Json对象。解决办法就是在web.xml中配置多个拦截请求:
web.xml(配置SpringMVC多个拦截请求):
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>e3-xxx-web</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- 解决post乱码 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding