$.ajax({url:"http://localhost:8080/TestApp/resources/Test",
type:"GET",
data:userName :"userName",
cache: false,
success:function(result){
alert(result);
},
});
以上是我用來調用服務的JQuery代碼。我怎樣才能獲得userName
參數到將來自JQuery/Ajax調用的參數數據傳遞給Jersey web服務
@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) 在 融爲一體。 sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider $ TypeOutInvoker._dispatch(AbstractResourceMethod DispatchProvider.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)
做了更改並獲得如上的異常。
@QueryParam得到正確價值,並在您的更改後它工作正常。非常感謝 :) – Yasothar