Calling a servlet during the page load time | Community
Skip to main content
Level 7
March 25, 2024
Solved

Calling a servlet during the page load time

  • March 25, 2024
  • 1 reply
  • 667 views

Hello Everyone,

 

How can I call my servlet during page load time?

I know below mentioned approach.

 

 

Added this ajax call in some genral js file. $.ajax({ url: "/content/data/practice/servlet/dummyServlet", type: "GET", data: { testParam: "testVal" }, success: function (response) { console.log("Yes"); }, error: function (error) { console.log("Error in sso login Url response", error); }, }); jcr path: /content/data/practice/servlet/dummyServlet has sling:resourceType /apps/test/testURL So, this called my servlet file @Component(service = Servlet.class, property = { "sling.servlet.resourceTypes=" + "/apps/test/testURL", "sling.servlet.methods=GET" }, immediate = true) public class MyServlet extends SlingAllMethodsServlet { //doGet method }​

 

Is there any other way to call the servlet during page load time?

 

In a page I have added the component: /apps/abc/components/tagresult

I have created the below mentioned servlet with resource type as well. Will this work ?

 

@8220494(service = Servlet.class, property = { "sling.servlet.resourceTypes=" + "abc/components/tagresult", "sling.servlet.methods=GET" }, immediate = true) public class CompServlet extends SlingAllMethodsServlet { //doGet method }

 

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 Mahesh_Gunaje

Hi Everyone,

 

Ignore my above query.

 

 

(service = Servlet.class, property = { "sling.servlet.resourceTypes=" + "abc/components/tagresult", "sling.servlet.methods=GET", "sling.servlet.extensions=html" }, immediate = true) public class CompServlet extends SlingAllMethodsServlet { //do get method }

 

"sling.servlet.extensions=html"  this resolved my issue. Now, if I open the page: http://localhost:4502/editor.html/content/abc/us/en.html this will call my servlet.

Since this page has my component.

 

Sorry for the trouble.

 

1 reply

Mahesh_GunajeAuthorAccepted solution
Level 7
March 25, 2024

Hi Everyone,

 

Ignore my above query.

 

 

(service = Servlet.class, property = { "sling.servlet.resourceTypes=" + "abc/components/tagresult", "sling.servlet.methods=GET", "sling.servlet.extensions=html" }, immediate = true) public class CompServlet extends SlingAllMethodsServlet { //do get method }

 

"sling.servlet.extensions=html"  this resolved my issue. Now, if I open the page: http://localhost:4502/editor.html/content/abc/us/en.html this will call my servlet.

Since this page has my component.

 

Sorry for the trouble.