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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Sling servlet binding using resourceTypes,is it visible in Sling Servlet Resolver ?

Avatar

Level 2

Hi Team,

I have created one simple servlet using resourceTypes ,

Below is my code snippet  "

@Component(service=Servlet.class ,property={ Constants.SERVICE_DESCRIPTION + "=Simple Medicine Servlet",

"sling.servlet.methods=" + HttpConstants.METHOD_GET, "sling.servlet.paths=" + "/bin/mySimpleservlet1",

"sling.servlet.resourceTypes=" + "p1App/components/structure/samplePage" , "sling.servlet.selectors=" + "groups"})

public class ResourceServlet extends SlingSafeMethodsServlet{

private static final long serialVersionUID = 1L;

@Override

protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)

throws ServletException, IOException {

PrintWriter out = response.getWriter();

out.println("Servlet is called by resourceType!!!!!");}

}"

Case 1: By Path

When i hit the URL localhost:4502/bin/mySimpleservlet1  on browser getting output Servlet is called by resourceType!!!!!

&  I am looking in Sling Servlet Resolver , by Path is visible.

To call above servlet i wrote Ajax call as well ,

$.ajax({

         type: 'GET',   

         url: 'bin/mySimpleServlet1',

         data:{"pageurl":"/content/p1App/mypage/jcr:content/par/mastercomponent/medicine"},

         success: function(msg){

                     console.log(msg);  }

     });

Case 2 : By resourceTypes

When i hit the URL localhost:4502/content/mypage.groups.html on browser getting output Servlet is called by resourceType!!!!!

&  I am looking in Sling Servlet Resolver resourceTypes is not visible.

a) Can we see th servlet by resourceTypes is resolved in Sling Servlet Resolver ?

b) Can you please tell what to mention in ajax call to get servlet using resourceTypes?

Also let me know if you need more details.

Thanks in advance.

Regards,

Pavan

2 Replies

Avatar

Level 2

@aem_marc ,@smacdonald2008 Guys , can you please help me out ?

Avatar

Employee Advisor

What is the resource type of /content/mypage (visible as property in /content/mypage/jcr:content)? It should be "p1App/components/structure/samplePage".

Jörg