Unable to deploy SlingServlet in CQ

前端 未结 1 1291
感动是毒
感动是毒 2020-12-11 23:23

I\'m trying to create a servlet in CQ to access some back-end services. Then from my page will make an AJAX call to get the response from servlet.



        
相关标签:
1条回答
  • 2020-12-11 23:47

    You have got your properties wrong. Kindly refer to the sling docs to know what each property that you have set does.

    The property sling.servlet.paths should be used instead of sling.servlet.resourceTypes to provide the path under which the servlet is accessible as a Resource.

    Thus for your requirement, the following annotations would suffice.

    sling.servlet.methods - For the request methods supported by the servlet.

    sling.servlet.paths - For the request path that is handled by this servlet.

    @Component(immediate = true, metatype = false, label = "feedServlet")
    @Service(Servlet.class)
    @Properties(value = {
        @org.apache.felix.scr.annotations.Property(name = "sling.servlet.methods", value = "POST"),
        @org.apache.felix.scr.annotations.Property(name = "sling.servlet.paths", value ="/bin/feedServlet"))
    })
    public class FeedServlet extends SlingAllMethodsServlet {
    
        private static final long serialVersionUID = -2139716879248038562L;
    
        @Override
        protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServerException,
                IOException {
    
            String feed = "test test test";
    
            response.getWriter().write(feed);
        }
    }
    
    0 讨论(0)
提交回复
热议问题