Expand my Community achievements bar.

Elevate your expertise and be recognized as a true influencer! Nominations for the exclusive Adobe Community Advisor program 2023 are now OPEN.

How to pull the servlet resource and request parameters into HTL script and assign dynamically


Level 4

1) Currently i'm providing static URL path as datasource instead of servlet path, i tried the below method from pagination but not working

  1. dataSource: function(done) {
  2.   $.ajax({
  3.   type: 'GET',
  4.   url: '/bin/amica/searchResultsServlet?q=' + 'queryString',
  5.   success: function(response) {
  6.    done(response);
  7.    }
  8.    });
  9. }

2) How to include query parameters in HTL script. For example I need to get the parameter value 'q'' attribute it to queryString dynamically after every request?



               dataSource: 'http://localhost:8080/bin/amica/searchServlet?q= + 'queryString',

        locator: 'searchResults',

        pageSize: 5,

        prevText: "Previous",

        nextText: "Next",

        callback: function(data, pagination) {

            var html = template(data);




2 Replies


Level 10

What are you trying to do. As far as i can see - you are performing a GET operation to a Servlet from HTL component. Now, what - do you want to write the data returned from the GET operation to the HTL component?


Level 8


Just sharing few thoughts on above :

1] It is preferred to use servlet resolution by resource type[sling.servlet.resourceTypes] than by path[which you have implemented].

2] For pagination[probably another way without servlet would be to] use the result provided by the querbuilder "searchResult = query.getResult();" in the model where querybuilder is used and get the pagination to work.

3] To get the query parameter in model class, 


    private SlingHttpServletRequest request;

searchTerm = request.getParameter("q"); should work.