An end user filling in a CQ form and posting the data to a Sling Servlet
The Sling Servlet that is created encodes the submitted form data into JSON formatted data and returns the data to the web client where it is displayed.
A web application displaying JSON formatted data returned by a Sling Servlet
A custom Sling Servlet is an OSGi bundle. However, a difference between an OSGi bundle that contains service and an OSGi bundle that contains a Sling Servlet is the former requires that you create an instance of the service. For example, assume that an OSGi bundle contains a service based on a Java class named com.adobe.cq.CustomerService. To get data from the client web page to this OSGi service, you have to create an instance of com.adobe.cq.CustomerService, as shown in this example.
com.adobe.cq.CustomerService cs = sling.getService(com.adobe.cq.CustomerService.class);
Then you invoke a service method, as shown in this example that invokes the injestCustData method.
cs.injestCustData(first, last, phone, desc) ;
For information about how to create an Adobe CQ application that builds an OSGi bundle that contains a service (not a Sling Servlet), see Querying Adobe Experience Manager Data using the JCR API.
In contrast, when working with an OSGi bundle that contains a Sling Servlet, you post data to the Sling Servlet's doPost method. That is, you can use a JQuery AJAX request to post data to the Sling Servlet, as shown in the following example.
//Use JQuery AJAX request to post data to a Sling Servlet
$.ajax({
type: 'POST',
url:'/bin/mySearchServlet',
data:'id='+ claimId+'&firstName='+ myFirst+'&lastName='+ myLast+'&address='+ address+'&cat='+ cat+'&state='+ state+'&details='+ details+'&date='+ date+'&city='+ city,
success: function(msg){
alert(msg); //display the data returned by the servlet
}
});
This article discusses how to use Maven to develop the Sling Servlet, how to deploy it, and then how to post data to it from a client web page.
To read this development article, click:
http://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html
No comments:
Post a Comment
If you have any doubts or questions, please let us know.