Call controller method in SPRINGMVC project to report 406 error

Source: Internet
Author: User

Added annotations to the Controller class's methods: @ResponseBody

Page throws Error:

The resource identified by this request is a capable of generating responses with characteristics not acceptable accord ing to the request "accept" headers ()

The Web page can successfully dial in the method, but the returned JSON results are not received properly, and the page throws the above error.

Workaround:

In the Applicationcontext.xml header, add:

Xmlns:mvc= "Http://www.springframework.org/schema/mvc"

Add after Xsi:schemalocation:

Http://www.springframework.org/schema/mvc
Http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd

Add MVC Annotations:<mvc:annotation-driven/>


Then, remove the following in the configuration file:

<bean class= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>


By the way,<mvc:annotation-driven/> 's meaning:

<mvc:annotation-driven/> will automatically register defaultannotationhandlermapping and annotationmethodhandleradapter two beans, is required by spring MVC to distribute the request to @controllers.


Call controller method in SPRINGMVC project to report 406 error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.