Solution to 406 error still reported after SpringMVC joins the jackon package

  In springmvc, when we add @responsebody annotation and hope to return a json object, a 406 error will often occur


First of all 1. We need to check whether jackson's package has been imported, if not, import it




          2. Is the annotation configuration added to the springmvc configuration file?

       
<mvc:annotation-driven />

     
          
           3. Check the springmvc interception configuration in web.xml, if it is *.html, you need to modify it, because the suffix is ​​html and cannot respond to json data, you need to modify the suffix name. Change it to /, *.action and the like.

            If you don’t modify it, you can add another interception configuration yourself
    as follows:
<servlet-mapping>
		<servlet-name>taotao-portal</servlet-name>
		<!-- 伪静态化 -->
		<url-pattern>*.html</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>taotao-portal</servlet-name>
		<!-- 伪静态化 -->
		<url-pattern>*.action</url-pattern>
	</servlet-mapping>

       At this time, the suffix of the request that reported 406 error is replaced with .action, there is no problem

Guess you like

Origin blog.csdn.net/a447332241/article/details/77093840