$.ajax({url:"http://localhost:8080/TestApp/resources/Test",
type:"GET",
data:userName :"userName",
cache: false,
success:function(result){
alert(result);
},
});
上面是我用来调用服务的JQuery代码。如何获取
userName
参数 @GET
@Produces("text/html")
public String getHtml() {
return "Hello ";
}
类似于servlet中的
request.getParameter("")
。在我的低估中,@QueryParam
,@PathParam
,@FormParam
用于不同的目的,或者可以用于获取参数。 (我已经尝试了所有三个都失败了)。如果我做错了什么,请纠正我。无法将RuntimeException映射到响应,然后重新抛出
HTTP容器com.sun.jersey.api.container.ContainerException:
在以下位置获取异常的参数
com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:54)
在
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider $ EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:137)
在
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider $ TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:165)
在
com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:70)
在
com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:279)
在
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:86)
在
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
做了更改,并得到了如上所述的例外。
最佳答案
data属性必须是普通的js对象,String或数组(请参见http://api.jquery.com/jquery.ajax/)
因此,在您的代码中,数据元素应为
data:{userName:'UserName'}
关于java - 将参数数据从JQuery/Ajax调用传递到Jersey Web服务,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30730400/