【问题标题】:Sling servlet invalid recursion selector with json extension带有 json 扩展名的 Sling servlet 无效递归选择器
【发布时间】:2018-06-20 21:12:26
【问题描述】:

我正在使用

注册一个 Sling Servlet
@Component(service=Servlet.class,
           property={
                   Constants.SERVICE_DESCRIPTION + "=Simple Demo Servlet",
                   "sling.servlet.methods=" + HttpConstants.METHOD_GET,
                   "sling.servlet.resourceTypes="+ "myapp/components/structure/page",
                   "sling.servlet.extensions=" + "json",
                   "sling.servlet.selectors=" + "myselector"
 })

但是当调用 URL <host:port>/content/myapp/en.myselector.js 时出现错误

Invalid recursion selector value 'myselector'
Cannot serve request to /content/myapp/en.myselector.json in 
org.apache.sling.servlets.get.DefaultGetServlet

如果我们从注解中删除"sling.servlet.extensions=" + "json",,我们可以使用<host:port>/content/myapp/en.myselector.js<host:port>/content/myapp/en.myselector.html 而不是<host:port>/content/myapp/en.myselector.json 来访问servlet

需要任何额外的配置吗?还是它与DefaultGetServlet 冲突?我们试图使用语义上有意义的 servlet 和 JSON 扩展从资源中公开 JSON。

【问题讨论】:

  • 您是否尝试过使用<host:port>/content/myapp/en/_jcr_content.myselector.json。由于您要针对资源注册 servlet,因此页面的资源类型将在 jcr:content 节点中,而不是在页面节点本身上。
  • 感谢@rakhi4110,它适用于jcr:content。 I think when both selector and extension is there path till jcr:content is required, else if only selector is there it works without jcr:content for .js of .html.您可以发布答案,我可以接受。

标签: aem sling


【解决方案1】:

由于您针对资源而不是路径注册了 servlet,因此资源实际上是页面的 jcr:content 节点,而不是页面节点本身。

因此,当使用 URL 中的 jcr:content 访问时,servlet 应该可以工作,如下所示

<host:port>/content/myapp/en/_jcr_content.myselector.json

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-21
    • 1970-01-01
    • 1970-01-01
    • 2013-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多