Javascript ajax和spring mvc出现406(不可接受)错误

Javascript ajax和spring mvc出现406(不可接受)错误,javascript,ajax,spring,spring-mvc,Javascript,Ajax,Spring,Spring Mvc,我有这个问题GEThttp://localhost:8080/yous/ajaxtest 406(不可接受) 下面是我使用ajax处理登录表单的脚本: function ajaxtest() { $.ajax({ url : 'ajaxtest', success : function(responce) { if(responce) $('#f

我有这个问题
GEThttp://localhost:8080/yous/ajaxtest 406(不可接受)

下面是我使用ajax处理登录表单的脚本:

        function ajaxtest() {
        $.ajax({
            url : 'ajaxtest',
            success : function(responce) {
                if(responce)
                    $('#formlogin').submit();
                else
                $('#errorlogin').html("Le nom d'utilisateur ou le mot de passe saisi est incorrect.");
            }
        });
       }
我的控制器:

    @RequestMapping(value = "/ajaxtest")
    public @ResponseBody
    boolean  ajaxtest(@ModelAttribute(value="auth") Auth auth) {

    List<Auth> listlogin = authDao.findByProperty("login", auth.getLogin(), "pwd", auth.getPwd());
    if(listlogin.size() == 1)
        return true;    
    return false;
    }
@RequestMapping(value=“/ajaxtest”)
公共@ResponseBody
布尔ajaxtest(@ModelAttribute(value=“auth”)auth auth){
List listlogin=authDao.findByProperty(“login”,auth.getLogin(),“pwd”,auth.getPwd());
if(listlogin.size()==1)
返回true;
返回false;
}

另一个我对ajax不熟悉的问题是,我听到很多关于发送请求的JSON是处理ajax的最佳方法吗?

当处理程序方法用
@ResponseBody
注释时,Spring通常会生成一个JSON响应体,将响应
内容类型设置为
应用程序/JSON
。如果您的请求中没有该媒体类型的
Accept
头,Spring将认为响应不可接受并返回406错误代码

您需要在ajax请求中指定
Accept

headers: { 
    Accept : "application/json"
}

使用合适的媒体类型。

我刚刚添加了这个依赖项,它的工作:)


org.codehaus.jackson
杰克逊地图绘制者
1.9.13

当我使用GET方法发送地址电子邮件时,我遇到了同样的问题。我用POST方法解决了我的问题

    <!-- Jackson JSON Mapper -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.13</version>
    </dependency>