@Service(value = Servlet.class)
@SlingServlet(paths = { "/bin/myServlet" }, methods = { "POST" }, metatype = false)
public class HandleClaim extends SlingAllMethodsServlet {
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
ResourceResolver resourceResolver = request.getResourceResolver();
Resource resource = resourceResolver.getResource("/etc/tags/ffb/faq/");
JSONObject namesObject;
JSONArray namesList = new JSONArray();
JSONObject namesListObject = new JSONObject();
JSONArray tagnames = ListAllTags(resource);
try {
for (int i = 0; i < tagnames.length(); i++) {
namesObject = new JSONObject();
namesObject.put("text", tagnames.get(i));
namesObject.put("value", tagnames.get(i));
namesList.put(namesObject);
}
namesListObject.put("categories", namesList);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response.setContentType("text/plain");
response.getWriter().write(namesListObject.toString());
}
public JSONArray ListAllTags(Resource resource) {
JSONArray categoryArray = new JSONArray();
if(resource!=null) {
Iterable<Resource> check = resource.getChildren();
for (Resource test : check) {
categoryArray.put(test.getName());
}
}
return categoryArray;
}
}
Please tell me what i'm doing wrong.