How to request for a servlet if we specify resourceTypes , extensions and selectors in @SlingServlet | Community
Skip to main content
Level 3
May 7, 2016
Solved

How to request for a servlet if we specify resourceTypes , extensions and selectors in @SlingServlet

  • May 7, 2016
  • 2 replies
  • 940 views

Hi,


import java.io.IOException;
import javax.jcr.Repository;
import javax.servlet.ServletException;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;

@SlingServlet(resourceTypes="/libs/myFirstApp/company/repo", selectors ="a4",extensions="html")
public class MySafeMethodServlet extends SlingSafeMethodsServlet {
    private static final long serialVersionUID = -3960692666512058118L;
    @Reference
    private Repository repository;
    @Override
    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
        response.setHeader("Content-Type", "application/json");
        response.getWriter().print("{\"coming\" : \"soon\"}");
        response.getWriter().print("Welcome");
       
    
    }
    
}

The above one is my servlet. How should I send a request to get the response from this servlet

I tried it as  http://localhost:4502/libs/myFirstApp/company/repo.a4.html   

But Page not found (404) error coming. Please help me regarding this.

 

Thanks

Best Regards,

Vijaya

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 edubey

Hi, 

In short you need to request for a resource for which resource type is wht u have given in servlet.

It can be a page which is having resourceType as /libs/myFirstApp/company/repo

This Helpx article explains these in detail https://helpx.adobe.com/experience-manager/using/resourcetypes.html

Thanks

2 replies

edubey
edubeyAccepted solution
Level 10
May 7, 2016

Hi, 

In short you need to request for a resource for which resource type is wht u have given in servlet.

It can be a page which is having resourceType as /libs/myFirstApp/company/repo

This Helpx article explains these in detail https://helpx.adobe.com/experience-manager/using/resourcetypes.html

Thanks

kautuk_sahni
Community Manager
Community Manager
May 9, 2016

Hi

As mentioned by Praveen, [1] is excellent article to be considered.

[1] = https://helpx.adobe.com/experience-manager/using/resourcetypes.html

 

Adding one more reference link:-  http://stackoverflow.com/questions/29102285/how-to-invoke-sling-servlet-that-uses-resourcetype-instead-of-paths-in-slin

I hope this would be of some use to you.

 

Thanks and Regards

Kautuk Sahni

Kautuk Sahni