How to hit a servlet using selector when resourceType is a component I created which is not page | Community
Skip to main content
New Participant
November 23, 2020
Solved

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

  • November 23, 2020
  • 2 replies
  • 10220 views

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.

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 Anudeep_Garnepudi

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

 

2 replies

Ankur_Khare
New Participant
November 23, 2020

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

Anudeep_Garnepudi
Anudeep_GarnepudiAccepted solution
New Participant
November 23, 2020

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

 

New Participant
November 23, 2020
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?