============ Internet of Things ============================= ================================================================ This is a "hello world" example using JSON and AJAX. A Javascript JSON parsing libary is in IntelliJ under the Web Pages folder. This file is named "json_sans_eval.js". A very small Javascript file is also under the Web Pages folder and is shown next: Its name is "GetJSON.js". ================================================================ function getSomeJSON() { var xhr; if(window.XMLHttpRequest) xhr = new XMLHttpRequest(); else xhr = ActiveXObject("Microsoft.XMLHTTP"); xhr.onreadystatechange = function() { // handle callback by calling handleJSON if(xhr.readyState == 4) { var result = xhr.responseText; handleJSON(result); } } // Visit the servlet xhr.open("GET", "JSONHelloServlet",true); xhr.send(null); } // handle response function handleJSON(someJSONFromServer) { // Use library to parse the string back from server var myJsonObj = jsonParse(someJSONFromServer); // Find the value of the Hello identifier var returnedValue = myJsonObj.Hello; // Place the returnedValue in the DOM. // The id coolLocation is used to find the location. var contents = document.getElementById("coolLocation"); // Erase current value contents.innerHTML = ""; // Add the value of the JSON name, value pair. contents.appendChild(document.createTextNode(returnedValue)); } ================================================================= Shown next is the index.jsp page. ================================================================= <%-- Document : index Created on : September 2019, 10:56:01 PM Author : mm6 --% <%@page contentType="text/html" pageEncoding="UTF-8"%>