I want to create a REST Jersey Web-Service accepting JSON string as input parameter.
Also I will use post requestand from webmethod I will return one JSON string.
How can I consume this in a HTML page using Ajax post request.
I want to know what all changes I need to make it on web method to accept JSON String.
public class Hello {
@POST
public String sayPlainTextHello() {
return "Hello Jersey";
}
}
Need to break down your requests. First, you want to accept a JSON string. So on your method you need
Next, you need to decide what you want your method to obtain. You can obtain a JSON string, as you suggest, in which case your method would look like this:
Or alternatively if your JSON string maps to a Java object you could take the object directly:
You state that you want to return a JSON string. So you need:
And then you need to actually return a JSON string:
So your full method looks something like this:
Regarding using AJAX to send and receive, it would look something like this: