How can I generate below given json sample through java servlet page? And then how to retrieve in html- javascript page?
Required Json sample:
[{user:"1s",item:123},{user:"2w",item:143},{user:"f2",item:125}]
Which can be used JsonArray or JsonObject? or both ..?
Use json.org JSON library for Java. Create a JSON object, load it, pipe the string output (.toString()) to the output stream in the
doGetmethod in yourHttpServlet.http://json.org/java/
On the JavaScript side, get the JSON string with
XMLHttpRequestthen convert it to a JavaScript object withJSON.parse.