/** * Gets the list JSON data. * * @param tasks task iterator * @return list JSON data */ private void getJson(Iterator<Document> documents) throws IOException { StringBuilder jsonBuilder = new StringBuilder("{"); while (documents.hasNext()) { Document instance = documents.next(); int id = instance.getId(); String name = instance.getName(); jsonBuilder.append("\"").append(id).append("\":\"").append(name).append("\""); if (documents.hasNext()) { jsonBuilder.append(","); } } jsonBuilder.append("}"); // Returns JSON data back to page HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html;charset=UTF-8"); response.getWriter().write(jsonBuilder.toString()); }