Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

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

Avatar

Level 4

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

1 Accepted Solution

Avatar

Correct answer by
Level 10

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

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

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

Avatar

Administrator

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-inste...

I hope this would be of some use to you.

 

Thanks and Regards

Kautuk Sahni



Kautuk Sahni