{"id":23779,"date":"2015-08-04T00:31:04","date_gmt":"2015-08-03T19:01:04","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=23779"},"modified":"2015-08-04T09:49:44","modified_gmt":"2015-08-04T04:19:44","slug":"registering-a-servlet-for-every-page-in-aem","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/registering-a-servlet-for-every-page-in-aem\/","title":{"rendered":"Registering a Servlet for every Page in AEM"},"content":{"rendered":"<p><strong>UseCase<\/strong>: &#8211; I had a situation in which needed to return custom information corresponding to every page in AEM and also use it via component to display to end user .<\/p>\n<p>-Then i have to invoke a Servlet on every page and with the use of selector want to return some information in JSON Format which can be used to display via Component on a Page to end user .<\/p>\n<p><strong>Solution<\/strong> : -For such situations we use the resourceType as <strong>cq\/Page<\/strong> for registering Servlet , so that Servlet is registered for every Page.<\/p>\n<p>&#8211; Then with the use of a particular selector we can get results like list information\/required custom information for every AEM page and display either via component with its ajax request has a url of Current Page.Selector which invokes the Servlet and renders result .<\/p>\n<p><strong>Note<\/strong>: &#8211; Just for reference Sling resolves on basis of Primary Type example cq:Page for Page and dam:Asset for Dam in case sling:resourceType is missing .<\/p>\n<p>Code Snippet :<\/p>\n<p>[java]<br \/>\n@Component(name = &quot;Site-Results&quot;, metatype = false, configurationFactory = false, policy = ConfigurationPolicy.OPTIONAL)<br \/>\n@Service(Servlet.class)<br \/>\n@Properties([<br \/>\n    @Property(name = &quot;sling.servlet.resourceTypes&quot;, value = [&quot;cq\/Page&quot;]),<br \/>\n    @Property(name = &quot;sling.servlet.selectors&quot;, value = &quot;results&quot;),<br \/>\n    @Property(name = &quot;sling.servlet.extensions&quot;, value = [&quot;json&quot;]),<br \/>\n    @Property(name = &quot;sling.servlet.methods&quot;, value = &quot;GET&quot;),<br \/>\n    @Property(name = &quot;sling.servlet.description&quot;, value = &quot;Gives Results for Every Page&quot;)<br \/>\n])<br \/>\nclass ResultsServlet extends SlingSafeMethodsServlet {<\/p>\n<p>    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) {<\/p>\n<p>\/\/Implement Your Logic<\/p>\n<p>}<\/p>\n<p>}<br \/>\n[\/java]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>UseCase: &#8211; I had a situation in which needed to return custom information corresponding to every page in AEM and also use it via component to display to end user . -Then i have to invoke a Servlet on every page and with the use of selector want to return some information in JSON Format [&hellip;]<\/p>\n","protected":false},"author":127,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":85,"footnotes":""},"categories":[1],"tags":[1235,4847,2114],"class_list":["post-23779","post","type-post","status-publish","format-standard","hentry","category-technology","tag-adobe-cq5","tag-aem","tag-servlet-in-aem"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"UseCase: - I had a situation in which needed to return custom information corresponding to every page in AEM and also use it via component to display to end user . -Then i have to invoke a Servlet on every page and with the use of selector want to return some information in JSON Format\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Deepak Khetawat\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/registering-a-servlet-for-every-page-in-aem\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Registering a Servlet for every Page in AEM | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"UseCase: - I had a situation in which needed to return custom information corresponding to every page in AEM and also use it via component to display to end user . -Then i have to invoke a Servlet on every page and with the use of selector want to return some information in JSON Format\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/registering-a-servlet-for-every-page-in-aem\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Registering a Servlet for every Page in AEM | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"UseCase: - I had a situation in which needed to return custom information corresponding to every page in AEM and also use it via component to display to end user . -Then i have to invoke a Servlet on every page and with the use of selector want to return some information in JSON Format\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/registering-a-servlet-for-every-page-in-aem\\\/#article\",\"name\":\"Registering a Servlet for every Page in AEM | TO THE NEW Blog\",\"headline\":\"Registering a Servlet for every Page in AEM\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/deepak-khetawat\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2015-08-04T00:31:04+05:30\",\"dateModified\":\"2015-08-04T09:49:44+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":3,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/registering-a-servlet-for-every-page-in-aem\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/registering-a-servlet-for-every-page-in-aem\\\/#webpage\"},\"articleSection\":\"Technology, Adobe cq5, AEM, Servlet in AEM\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/registering-a-servlet-for-every-page-in-aem\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"position\":2,\"name\":\"Technology\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/registering-a-servlet-for-every-page-in-aem\\\/#listItem\",\"name\":\"Registering a Servlet for every Page in AEM\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/registering-a-servlet-for-every-page-in-aem\\\/#listItem\",\"position\":3,\"name\":\"Registering a Servlet for every Page in AEM\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/deepak-khetawat\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/deepak-khetawat\\\/\",\"name\":\"Deepak Khetawat\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/registering-a-servlet-for-every-page-in-aem\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b190b67254f5d463a462bf1d5f2f509cdca455f01d2e29e8c40b8f72e41e8b22?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Deepak Khetawat\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/registering-a-servlet-for-every-page-in-aem\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/registering-a-servlet-for-every-page-in-aem\\\/\",\"name\":\"Registering a Servlet for every Page in AEM | TO THE NEW Blog\",\"description\":\"UseCase: - I had a situation in which needed to return custom information corresponding to every page in AEM and also use it via component to display to end user . -Then i have to invoke a Servlet on every page and with the use of selector want to return some information in JSON Format\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/registering-a-servlet-for-every-page-in-aem\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/deepak-khetawat\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/deepak-khetawat\\\/#author\"},\"datePublished\":\"2015-08-04T00:31:04+05:30\",\"dateModified\":\"2015-08-04T09:49:44+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Registering a Servlet for every Page in AEM | TO THE NEW Blog","description":"UseCase: - I had a situation in which needed to return custom information corresponding to every page in AEM and also use it via component to display to end user . -Then i have to invoke a Servlet on every page and with the use of selector want to return some information in JSON Format","canonical_url":"https:\/\/www.tothenew.com\/blog\/registering-a-servlet-for-every-page-in-aem\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/registering-a-servlet-for-every-page-in-aem\/#article","name":"Registering a Servlet for every Page in AEM | TO THE NEW Blog","headline":"Registering a Servlet for every Page in AEM","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/deepak-khetawat\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"datePublished":"2015-08-04T00:31:04+05:30","dateModified":"2015-08-04T09:49:44+05:30","inLanguage":"en-US","commentCount":3,"mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/registering-a-servlet-for-every-page-in-aem\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/registering-a-servlet-for-every-page-in-aem\/#webpage"},"articleSection":"Technology, Adobe cq5, AEM, Servlet in AEM"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/registering-a-servlet-for-every-page-in-aem\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","name":"Technology"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","position":2,"name":"Technology","item":"https:\/\/www.tothenew.com\/blog\/category\/technology\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/registering-a-servlet-for-every-page-in-aem\/#listItem","name":"Registering a Servlet for every Page in AEM"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/registering-a-servlet-for-every-page-in-aem\/#listItem","position":3,"name":"Registering a Servlet for every Page in AEM","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","name":"Technology"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/deepak-khetawat\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/deepak-khetawat\/","name":"Deepak Khetawat","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/registering-a-servlet-for-every-page-in-aem\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/b190b67254f5d463a462bf1d5f2f509cdca455f01d2e29e8c40b8f72e41e8b22?s=96&d=mm&r=g","width":96,"height":96,"caption":"Deepak Khetawat"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/registering-a-servlet-for-every-page-in-aem\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/registering-a-servlet-for-every-page-in-aem\/","name":"Registering a Servlet for every Page in AEM | TO THE NEW Blog","description":"UseCase: - I had a situation in which needed to return custom information corresponding to every page in AEM and also use it via component to display to end user . -Then i have to invoke a Servlet on every page and with the use of selector want to return some information in JSON Format","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/registering-a-servlet-for-every-page-in-aem\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/deepak-khetawat\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/deepak-khetawat\/#author"},"datePublished":"2015-08-04T00:31:04+05:30","dateModified":"2015-08-04T09:49:44+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Registering a Servlet for every Page in AEM | TO THE NEW Blog","og:description":"UseCase: - I had a situation in which needed to return custom information corresponding to every page in AEM and also use it via component to display to end user . -Then i have to invoke a Servlet on every page and with the use of selector want to return some information in JSON Format","og:url":"https:\/\/www.tothenew.com\/blog\/registering-a-servlet-for-every-page-in-aem\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Registering a Servlet for every Page in AEM | TO THE NEW Blog","twitter:description":"UseCase: - I had a situation in which needed to return custom information corresponding to every page in AEM and also use it via component to display to end user . -Then i have to invoke a Servlet on every page and with the use of selector want to return some information in JSON Format","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"23779","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":"","og_description":"","og_object_type":"blog","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":"","og_article_tags":"","twitter_use_og":false,"twitter_card":"summary","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-29 14:52:09","updated":"2024-02-29 09:26:21","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/technology\/\" title=\"Technology\">Technology<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tRegistering a Servlet for every Page in AEM\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"Technology","link":"https:\/\/www.tothenew.com\/blog\/category\/technology\/"},{"label":"Registering a Servlet for every Page in AEM","link":"https:\/\/www.tothenew.com\/blog\/registering-a-servlet-for-every-page-in-aem\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/23779","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/127"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=23779"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/23779\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=23779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=23779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=23779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}