Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to post a JSON in JQuery to a server that GET the JSON in Jersey JAVA
    primarykey
    data
    text
    <p>Is it even possible to post a JSON in JQuery to a server that GET the JSON in Jersey JAVA, I'm struggling with the problem. I have a ajax posts a JSON to a server uses Jersey REST GET, but nothing is working, I'm wondering if its the right way to do it. Here is my previous questions with code regarding to the problem:</p> <p>code in java implements in the server:</p> <pre><code>@Path("/helloworld") public class GetData { @GET @Consumes("application/json") @Produces("application/json") public String getResource(JSONObject obj) throws IOException { InputStream in = (InputStream) obj.values(); String data = IOUtils.toString(in); JSONObject out = (JSONObject) JSONSerializer.toJSON(data); String result = out.getString("name"); return data; } } </code></pre> <p>Javascript code:</p> <pre><code>&lt;script&gt; $.ajax({ url: '/helloworld', type: 'POST', contentType: 'application/json', data: { json: JSON.stringify({ name:"Bob" })}, dataType: 'json' }); alert("json posted!"); &lt;/script&gt; </code></pre> <p>Message in server console:</p> <blockquote> <p>2012-apr-12 10:49:51 com.sun.jersey.spi.container.ContainerRequest getEntity ALLVARLIG: A message body reader for Java class net.sf.json.JSONObject, and Java type class net.sf.json.JSONObject, and MIME media type application/octet-stream was not found. The registered message body readers compatible with the MIME media type are: application/octet-stream -> com.sun.jersey.core.impl.provider.entity.ByteArrayProvider</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload