Using parameters in URLs in Jersey Web Services

I have demonstrated a couple of web service examples in my previous posts. I hope you have noticed that the URLs I have used for calling web services is not practical. I mean, URLs now a days are not quite like them. Normally, we use URLs with parameters.
e.g. - http://localhost:8080/Test/resources/test/search?name=Tom
Well, in this case, we will have to change the server in the following way -
   1: // URL - http://localhost:8080/Test/resources/test/search?name=Tom

   2: @GET

   3: @Path("/search")

   4: public String getUserDetailsFromAddress(

   5:         @QueryParam("name") String name) {

   6:     return "Hello"+name;

   7: }
And, in the client side also, we need to do some changes as well:


JSONArray resultArray = new JSONArray(service
.path("resources/test/search").queryParam("name", "Tom")
.get(String.class));

Well, that should do the trick !!




Related post : Creating web service with maven jersey
Feel free to share !!!

“Knowledge which is acquired under compulsion obtains no hold on the mind.” - Plato

No comments :

Post a Comment