Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

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

pillaivinit
Level 3
Level 3

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.

AEM aem6.3 servlet
1 Accepted Solution
Anudeep_Garnepudi
Correct answer by
Community Advisor
Community Advisor

Hi @pillaivinit 

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
Anudeep_Garnepudi
Correct answer by
Community Advisor
Community Advisor

Hi @pillaivinit 

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

pillaivinit
Level 3
Level 3
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?
Anudeep_Garnepudi
Community Advisor
Community Advisor
give a valid extension like html/json/txt. Give extension = "html" and selectors = {"selector"}
pillaivinit
Level 3
Level 3

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.

Anudeep_Garnepudi
Community Advisor
Community Advisor
If you hit http://localhost:4502/content/my-project/homepage/profile-page/test/en/par/my-component.html, showing authored component data?
Anudeep_Garnepudi
Community Advisor
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"
pillaivinit
Level 3
Level 3
/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)
pillaivinit
Level 3
Level 3
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.
Anudeep_Garnepudi
Community Advisor
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
pillaivinit
Level 3
Level 3

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

Anudeep_Garnepudi
Community Advisor
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.
pillaivinit
Level 3
Level 3
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.
Anudeep_Garnepudi
Community Advisor
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.
Ankur_Khare
Community Advisor
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