Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Servlet cannot be correctly instantiated by the Use API


Level 2



I am trying to achieve, sling servlet application using sightly.

But, it is showing “ Identifier cannot be correctly instantiated by the Use API”

Kindly help me in resolving this issue.



Maria Anto


Sightly code:

<!DOCTYPE html>
    <sly data-sly-use.css="${''}" data-sly-unwrap>
    <sly data-sly-use.clientLib="/libs/granite/sightly/templates/clientlib.html" data-sly-call="${clientLib.js @ categories='jquerysamples'}" data-sly-unwrap></sly> 
        <title>Survey Application</title>
        $(document).ready(function() {

            $('#submit').click(function() {
                var failure = function(err) {
                    alert("Unable to retrive data "+err);

                //Get the user-defined values that represent claim data to persist in the Adobe CQ JCR
                var qu1= $('#ques1').val() ; 
                var qu2= $('#ques2').val() ; 
                var qu3= $('#rating').val() ; 

                var resourcepath = $('#resourcepath').val();


                //Use JQuery AJAX request to post data to a Sling Servlet
                    type: 'POST',    
                    url: resourcepath +'.slingServlet.json',
                    data:'ques1='+ qu1+'&ques2='+ qu2+'&rating='+ qu3,
                    success: function(msg){
                        var json = jQuery.parseJSON(msg);           
                        var n = json.Q1;
                        $('#sub').val("Details updated !!"); 
        }); // end ready
    <input type="hidden" value="${resource.path}" id="resourcepath"/>  
        <form method="#">
            <table border="0" align="left">
                        <label for="ques1">1. How satisfied are you with the outcome / resolution of the complaint ?</label>
                        <input type="text" id="ques1" name="ques1" maxlength="10">
                        <label for="ques2">2. How satisfied are you with the time taken to give you a feedback / solution to your complaint ?</label>
                        <input type="text" id="ques2" name="ques1" maxlength="10">
                        <label for="ques3">3. How satisfied are you with the responsiveness of the complaint registered by you ?</label>
                        <select id="rating" name="ratingVal">
                            <option value="rat5">Rating 5</option>
                            <option value="rat4">Rating 4</option>
                            <option value="rat3">Rating 3</option>
                            <option value="rat2">Rating 2</option>
                            <option value="rat1">Rating 1</option>
                            <option value="NA">NA</option>
                        <label for="ques4" id="ques4">4. Have you received Compensation ?</label>
                        <input type="radio" name="yes" value="yes"> Yes  <input type="radio" name="no" value="no"> No
                        <label id="sub">Abc</label>
                        <input type="button" value="Submit" name="submit" id="submit">


Servlet code:


import java.rmi.ServerException;

import org.apache.felix.scr.annotations.Reference;
import org.json.simple.JSONObject;

resourceTypes = "cssurvey/components/content/css", 
selectors = "slingServlet",
extensions = "json",
methods = "POST")

public class SurveyServlet extends{
    private static final long serialVersionUID = 2598426539166789515L;
    private SlingRepository repository;
    public void bindRepository(SlingRepository repository) {
           this.repository = repository; 
    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServerException, IOException {
         String Qn1 = request.getParameter("question1");
         String Qn2 = request.getParameter("question2");
         String Qn3 = request.getParameter("rating");
         System.out.println("ques1: "+ques1);
         System.out.println("ques2: "+ques2);
         System.out.println("rating: "+ques3);
         //Encode the submitted form data to JSON
         JSONObject obj=new JSONObject();
            //Get the JSON formatted data    
         String jsonData = obj.toJSONString();
            //Return the JSON formatted data
     catch(Exception e)

0 Replies