0

this is my servlet where i am getting sorted array as response

    String[] myarray = new String[] {nameOne, nameTwo, nameThree, nameFour, nameFive};
 
    Arrays.sort(myarray, String.CASE_INSENSITIVE_ORDER);
    Gson gson=new Gson();
String jsonData=gson.toJson(myarray);

response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(jsonData);

below is my javascript code to get array elements as ordered list, my pronblem is i dont know how to access the array from servlet in this javascript.anyone pls explain how can i store the array in a variable (var str)

    var str=// i want to store the array from servlet in this variable
    var list = document.createElement("ol");
for (let i of str) {
  let item = document.createElement("li");
  item.innerHTML = i;
  list.appendChild(item);
}

document.getElementById("demoA").appendChild(list);
this is html code
<div id="demoA"></div>

I tried request dispatcher but it is useful for jsp files . if solution is to use req dispatcher then pls tell me jsp code to generate that array elementrs as ordered list in html.

0 Answers0