Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Call OSGI service from HTML or Javascript

Avatar

Former Community Member

Hi,

I have created a HTML page with a form, and an OSGI service to save the data and send email. I want to know whether it is possible to call the OSGI service using Javascript or HTML without the component?

The HTML page that I have created does not using the CQ template or component, it is just a pure HTML file with some Javascripts.

<form id="aForm" action="">

<input type="text" class="textbox" name="contactNumber" />

....

</form>

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Level 10

instead of a service, use a servlet and call the same using javascript or html. Refer [1] for the example

[1] https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

instead of a service, use a servlet and call the same using javascript or html. Refer [1] for the example

[1] https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

Avatar

Administrator

Hi 

Adding one more helpx reference for your help:-

Link:- https://helpx.adobe.com/experience-manager/using/first-osgi.html

// Once OSGI is deployed, 

We can call OSGI functions from JSP like:-

<%@include file="/libs/foundation/global.jsp"%>
<h1><%= properties.get("title", currentPage.getTitle()) %></h1>
<%
  
com.adobe.cq.KeyService keyService = sling.getService(com.adobe.cq.KeyService.class);
keyService.setKey(10) ;
String ff = keyService.getKey();
  
%>
  
<h2>This page invokes the AEM KeyService</h2>
<h3>The value of the key is: <%=ff%></h3>

 

Option 2:- 

As mentioned by Lokesh, invoking it by Ajex request.

Link:- https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

 

I hope this would be useful for you.

 

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Former Community Member

Hi,

I have tried to use the servlet, but I got this error by the empty CSRF token. May I know how to include this token in the html?

In the example article I have found https://helpx.adobe.com/experience-manager/using/custom-sling-servlets6_1.html, it is mentioned to use the <cq:includeClientLib categories="cq.jquery" /> 

In my case, I did not use the template JSP. Is there a way to include this CSRF token in HTML?