dn'我找不到适合课堂的语法元素

dn't find a grammar element for class

本文关键字:课堂 语法 元素 找不到 dn      更新时间:2023-09-26

我有一个jersey服务,正在尝试使用xmlhttprequest 调用它

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public SomeJsonClass myService(SomeClassName classObject) throws RuntimeException, IOException,
            InterruptedException {
//Some code to handle request
return jsonClassObject;

}

我试着用以下方式来称呼它:

 <!DOCTYPE html>
<html>
    <head>
        <title>jQuery</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    </head>
<body>
<p>Click the button to demonstrate the prompt box.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction()
{
    var json=prompt("Enter JSON");
    alert("JSON: "+json);
                var xhr = new XMLHttpRequest();
                xhr.open("post","http://localhost:8080/otp/rest/validate-otp");
                xhr.setRequestHeader("Content-Type","application/json;charset=UTF-8");
                xhr.responseType = "json";
                xhr.send(JSON.stringify(json));
}
</script>
</body>
</html>

当我尝试运行此代码时,收到"找不到类的语法元素"警告。当我尝试使用rest客户端发送相同的json时,服务会给出正确的响应。

这里可能有什么问题?

看看本文是否使用JAX-RS和Jersey使用jQuery和Java提供RESTful服务http://coenraets.org/blog/2011/12/restful-services-with-jquery-and-java-using-jax-rs-and-jersey/对你有帮助。