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 ?
@component(service = Servlet.class, property = { "sling.servlet.resourceTypes=" + "abc/components/tagresult",
"sling.servlet.methods=GET" }, immediate = true)
public class CompServlet extends SlingAllMethodsServlet {
//doGet method
}