Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

javax.jcr.nodetype.ConstraintViolationException: No default node type available for /bin/myServlet

Avatar

Level 3

Hi,
I'm new with AEM.
I'm trying to call Servlet using Ajax call. But getting javax.jcr.nodetype.ConstraintViolationException: No default node type available for /bin/myServlet exception.

My ajax code is:

$.ajax({

            type: 'POST',

            url:'/bin/myServlet',

            data:'path='+ path,

            success: function(msg){

               alert("Hello");

            }

        });

And my Java code is:

@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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
1 Reply

Avatar

Correct answer by
Community Advisor

HI,

In your Java code, remove "@Service" annotation.

Solution for similar subject available at -

Servlet issue in 6.1 upgrade (from 5.6.1)

Adobe Experience Manager Help | Submitting Adobe Experience Manager form data to Java Sling Servlets