Expand my Community achievements bar.

SOLVED

How to hit a servlet using selector when resourceType is a component I created which is not page

Avatar

Level 4

I'm using AEM 6.3

My servlet config is

@Component(service= Servlet.class,
        property={
                Constants.SERVICE_DESCRIPTION + "=Example Servlet",
                "sling.servlet.methods=" + HttpConstants.METHOD_GET,
                "sling.servlet.resourceTypes="+ "my-project/components/general/my-component ",
                "sling.servlet.extensions=" + "html",
                "sling.servlet.selectors=" + "simple"

        })

As you can see I'm not using a page as a resourceType so I'm a little confused. Can anyone tell me what will be the url to hit on browser so it runs my doGet Method. And yes My servlet works as I have tested it by giving path.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Vinit_Pillai 

Drop my-component in any page and hit that path along with extension and selector with which you registered Servlet. For example

  1. Create a page with name test-page
  2. Drop my-component in that page
  3. copy that path i.e /content/your-project/test-page/par/my-component.selector.extension and hit from browser

selector and extension must be same as you provided in 

sling.servlet.extensions
sling.servlet.selectors

 

View solution in original post

17 Replies

Avatar

Correct answer by
Community Advisor

Hi @Vinit_Pillai 

Drop my-component in any page and hit that path along with extension and selector with which you registered Servlet. For example

  1. Create a page with name test-page
  2. Drop my-component in that page
  3. copy that path i.e /content/your-project/test-page/par/my-component.selector.extension and hit from browser

selector and extension must be same as you provided in 

sling.servlet.extensions
sling.servlet.selectors

 

Avatar

Level 4
http://localhost:4502/editor.html/content/my_project/homepage/profile-page/test/en.html this is my page when I edit it and add my component. by your suggestion the url will be http://localhost:4502/content/my-project/homepage/profile-page/test/en/par/my-component.selector.extension by hitting this I'm getting 404. am I doing something wrong?

Avatar

Community Advisor
give a valid extension like html/json/txt. Give extension = "html" and selectors = {"selector"}

Avatar

Level 4

http://localhost:4502/content/my-project/homepage/profile-page/test/en/par/my-component.simple.html This is what I'm using. I have updated my code in question to be more realistic.

Avatar

Community Advisor
If you hit http://localhost:4502/content/my-project/homepage/profile-page/test/en/par/my-component.html, showing authored component data?

Avatar

Community Advisor
Can you go to CRXDE and check this path "/content/my-project/homepage/profile-page/test/en/par/my-component" exists or not. If yes check the node has sling:resourceType as "my-project/components/general/my-component"

Avatar

Level 4
/content/my-project/homepage/profile-page/test/en/jcr:content/par/my_component This is what I found with resourceType as my-component. (There is jcr:content between url)

Avatar

Level 4
http://localhost:4502/content/my-project/homepage/profile-page/test/en/jcr:content/par/my_component.simple.html well at least I'm not getting 404 but instead my component.html file is loaded without all the css.

Avatar

Community Advisor
I see, there is a extra space at the end "sling.servlet.resourceTypes="+ "my-project/components/general/my-component ", remove and try one. Hope this time it works

Avatar

Level 4

Thanks a lot. Such a silly mistake on my part. I had another question though. since we are talking in the url we see "par" in reality I have 2 parsys with different names. Is there a way to get the servlet working in both pasrs. I mean whichever parsys the author uses

Avatar

Community Advisor
It will work in any parsys, you just need to copy the component path under /content just like how you did now and hit it with selector and extension. That's it.

Avatar

Level 4
I have two parsys primary layout and secondary layout both the name of any one is required in url. if I use par instead of their name then I get 404.

Avatar

Community Advisor
Drop your my-component in parsys which/where you want and then copy that path and hit. Your my-component must be dropped inside your custom parsys.

Avatar

Community Advisor

Create a page and add ur component on that page, try to access that page with selectors and extension.

like-

https://localhost:4502/content/simpleproject/test.simple.html