Ошибка 406 при вызове ajax Spring mvc

Мне сложно исправить эту ошибку 406 с помощью Spring MVC. Я хочу сделать вызов Ajax и получить ответ json. Также я пытаюсь вывести этот json с помощью alert (js). Вот как я это реализую.

Мой контроллер:

    @RequestMapping(value="/search", headers="Accept=*/*", produces=MediaType.APPLICATION_JSON_VALUE) // no 'params' argument
    @ResponseBody
    public Customer findByFirstName() {
         Customer test = new Customer();
         test.setFirstName("test");
         return test;
     }

Покупатель:

    @Entity
    @Table(name="customer",catalog="revised_cws_db")
    public class Customer  implements java.io.Serializable {
        @Id @GeneratedValue(strategy=IDENTITY)
        @Column(name="id", unique=true, nullable=false)
        private int id;
        @Version @Temporal(TemporalType.TIMESTAMP)
        @Column(name="timestamp", nullable=false)
        private Date timestamp;
        @ManyToOne(fetch=FetchType.LAZY)
        @JoinColumn(name="address_id", nullable=false)
        private Address address;
        @Temporal(TemporalType.DATE)
        @Column(name="birth_date", nullable=false, length=10)
        private Date birthDate;
        @Column(name="first_name", nullable=false, length=45)
        private String firstName;
        @Column(name="middle_name", nullable=false, length=45)
        private String middleName;
       @Column(name="gender", nullable=false, length=45)
       private String gender;
       @Column(name="contact_number", length=45)
       private String contactNumber;
       @Column(name="family_members_count", nullable=false, length=45)
       private String familyMembersCount;
       @Column(name="occupation_id", nullable=false)
       private int occupationId;
       @Column(name="active", nullable=false)
       private boolean active;
       @OneToMany(fetch=FetchType.LAZY, mappedBy="customer")
       private Set<Issues> issueses = new HashSet<Issues>(0);
       @OneToMany(fetch=FetchType.LAZY, mappedBy="customer")
       private Set<Account> accounts = new HashSet<Account>(0);  
       public Customer() {
       }
       public Customer(int id, Address address, Date birthDate, String firstName, String middleName, String gender, String familyMembersCount, int occupationId, boolean active) {
            this.id = id;
            this.address = address;
            this.birthDate = birthDate;
            this.firstName = firstName;
            this.middleName = middleName;
            this.gender = gender;
            this.familyMembersCount = familyMembersCount;
            this.occupationId = occupationId;
            this.active = active;
       }
       public Customer(int id, Address address, Date birthDate, String firstName, String middleName, String gender, String contactNumber, String familyMembersCount, int occupationId, boolean active, Set<Issues> issueses, Set<Account> accounts) {
            this.id = id;
            this.address = address;
            this.birthDate = birthDate;
            this.firstName = firstName;
            this.middleName = middleName;
            this.gender = gender;
            this.contactNumber = contactNumber;
            this.familyMembersCount = familyMembersCount;
            this.occupationId = occupationId;
            this.active = active;
            this.issueses = issueses;
            this.accounts = accounts;
       }
       //getters, setters omitted

сервлет:

    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>

<mvc:annotation-driven/>

<context:component-scan base-package="com.controller" />

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="cacheSeconds" value="0" />
</bean>
<!--
Most controllers will use the ControllerClassNameHandlerMapping above, but
for the index controller we are using ParameterizableViewController, so we must
define an explicit mapping for it.
-->
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <props>
            <prop key="index.htm">indexController</prop>
        </props>
    </property>
</bean>

<bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"
      p:prefix="/WEB-INF/jsp/"
      p:suffix=".jsp" />

<!--
The index controller.
-->
<bean name="indexController"
      class="org.springframework.web.servlet.mvc.ParameterizableViewController"
      p:viewName="index" />

jsp:

    <%@taglib uri = "http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
     <html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script>
        $(document).ready(function() {
            $(".search-form").keyup(function() {
                if ($(this).val().length >= 2) {
                    $('#searchForm').submit();
                }
            });
            $('#searchForm').submit(function(event) {    
                $.ajax({
                    dataType: 'json',
                    data : $(this).serialize(),
                    url: $(this).attr("action"),
                    success: function( result ) {
                        alert("test");
                    }
                });
                event.preventDefault();
            });

        });
    </script>
</head>
<body>
    <h1>Customers</h1>
    <form  id="searchForm" action="search.htm">
        Search Customer:
        <input class="search-form" name="firstName" placeholder="First Name">
        <input type="submit">
    </form>
</body>

I already added the following jars:

  • Джексон-ядро-asl 1.9.13
  • Джексон-картограф asl 1.9.13
  • Джексон-ядро 2.4.4
  • Джексон-Databind 2.4.4
  • аннотации Джексона 2.4.4

Я не знаю, что случилось. Буду признателен за любые предложения.


person noob user    schedule 25.04.2015    source источник
comment
@rene, я не могу решить эту проблему. пожалуйста, уточните принятое решение   -  person noob user    schedule 25.04.2015
comment
@rene Я использую firebug, и я вижу, что заголовки запросов принимаются с этим значением application / json, text / javascript, /; q = 0,01   -  person noob user    schedule 25.04.2015
comment
Заголовки запроса не важны. Каковы заголовки ответа?   -  person rene    schedule 25.04.2015
comment
@rene, извини, я действительно не знаю. так как я должен это знать? Я использую netbeans с tomcat ..   -  person noob user    schedule 25.04.2015