I searched the internet a bit, looking for a way (correctly) for @ Use the application / json file in a web resource on my server.
I am using Glassfish application server, so it is a java resource.
javascvript code is called here:
var url="/MBC/pages/lives/"; var mygetrequest=new ajaxRequest(); mygetrequest.onreadystatechange=function(){ if (mygetrequest.readyState==4){ if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1){ var render=""; var JsonIn =JSON.parse(mygetrequest.responseText); if(JsonIn.error==undefined){ render="generic error"; } }else render=mygetrequest.responseText ; document.getElementById(div).innerHTML=render; }else{ render="An error has occured making the request"; } }; var json2Send = "{" + "boss:\""+location.href.substring(location.href.length-5,location.href.length-4)+"\"," ; if(document.newLive.bval.value=='') json2Send+="bands:[],"; else json2Send+="bands:["+document.newLive.bval.value+"],"; json2Send+="data:\""+document.newLive.dateEvent.value+"\"," + "address:{street:\""+document.newLive.street.value+"\"," + "number:\""+document.newLive.number.value+"\"," + "city:\""+document.newLive.city.value+"\"," + "region:\""+document.newLive.region.value+"\"," + "state:\""+document.newLive.state.value+"\"}" + "}"; mygetrequest.open("POST", url, true); mygetrequest.setRequestHeader("Content-type", "application/json"); mygetrequest.send(json2Send);
where json2Send is the json string that the client should send to the server.
here server side code is used instead:
@POST @Path("configLiveBand") @Consumes("application/json") @Produces("application/json") public String liveBandInsert(String jsonIn, @Context HttpServletRequest request) throws ParseException{
Now I ask you what I need to do for the server to read the json input string coming from javascript. Obviously, the method described above does not work. server returns
HTTP Status 405 - type Status report message descriptionThe specified HTTP method is not allowed for the requested resource ().
looking at my problem over the internet, I found solutions using the readline () method of the BufferedReader class. I do not like this solution. I prefer, if this is the way, to enter an input line by line instead of a json file.
any help is well received thanks