How to access a SlingServlet from Serverside JavaScript | Community
Skip to main content
New Participant
July 14, 2017
Solved

How to access a SlingServlet from Serverside JavaScript

  • July 14, 2017
  • 1 reply
  • 1020 views

Hi everyone,

I wrote a SlingServlet  at @SlingServlet(resourceTypes = "/apps/global-components/left-nav", selectors = "breadcrumb", extensions = "data")

It is just returning a JSON object that is a list of page paths.

What is the best way to access this SlingServlet from Serverside JavaScript? or from HTL?

I want to render the data doing something like this in HTL:

<div data-sly-use.breadcrumbs="breadcrumb.js">

     <div data-sly-list.path="${breadcrumbs.breadcrumbs}">

          <div>${path}</div>

     </div>

</div>

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

One option you have to invoke this from HTL is to use AJAX - then when you get back the data - you can populate HTML:

Adobe Experience Manager Help | Creating an AEM HTML Template Language Component that posts data using AJAX

Use a GET operation.

Another option - if you want to use HTL to get data from Java - write a class that uses WCMUsePojo instead of a Servlet.

1 reply

smacdonald2008
smacdonald2008Accepted solution
New Participant
July 17, 2017

One option you have to invoke this from HTL is to use AJAX - then when you get back the data - you can populate HTML:

Adobe Experience Manager Help | Creating an AEM HTML Template Language Component that posts data using AJAX

Use a GET operation.

Another option - if you want to use HTL to get data from Java - write a class that uses WCMUsePojo instead of a Servlet.