Aem 跟踪和解决问题;选择器与变量的使用

Aem 跟踪和解决问题;选择器与变量的使用,aem,sling,Aem,Sling,在AdobeAEM(又名cq)中,对于给定的url,是否可以看到正在调用的jsp 我们有一些示例代码,不是由我们编写的,如果存在或不存在特定的选择器,则会匹配两组“基本”jsp-“m”用于mobile。 在基本jsp中,如果移动或桌面设备正在请求,则将一个变量设置为flag 从那时起,不再使用其他选择器——只需检查变量是否包含特定于移动设备的jsp 与单独使用选择器调用或不调用特定jsp不同的方法 通过跟踪脚本分辨率,它有助于可视化和首次出现,但这是基于sling的代码的常见模式吗?您可以在We

在AdobeAEM(又名cq)中,对于给定的url,是否可以看到正在调用的jsp

我们有一些示例代码,不是由我们编写的,如果存在或不存在特定的选择器,则会匹配两组“基本”jsp-“m”用于mobile。 在基本jsp中,如果移动或桌面设备正在请求,则将一个变量设置为flag

从那时起,不再使用其他选择器——只需检查变量是否包含特定于移动设备的jsp

与单独使用选择器调用或不调用特定jsp不同的方法


通过跟踪脚本分辨率,它有助于可视化和首次出现,但这是基于sling的代码的常见模式吗?

您可以在Web控制台的“最近的请求”选项卡(
http://localhost:4502/system/console/requests
用于本地作者实例)

输出类似于下面的输出,它应该为您提供足够的信息

  0 (2013-09-14 21:36:20) TIMER_START{Request Processing}
  0 (2013-09-14 21:36:20) COMMENT timer_end format is {<elapsed msec>,<timer name>} <optional message>
  0 (2013-09-14 21:36:20) LOG Method=GET, PathInfo=/.edit.html
  0 (2013-09-14 21:36:20) TIMER_START{ResourceResolution}
  1 (2013-09-14 21:36:20) TIMER_END{1,ResourceResolution} URI=/.edit.html resolves to Resource=JcrNodeResource, type=sling:redirect, superType=null, path=/
  1 (2013-09-14 21:36:20) LOG Resource Path Info: SlingRequestPathInfo: path='/', selectorString='edit', extension='html', suffix='null'
  1 (2013-09-14 21:36:20) TIMER_START{ServletResolution}
  1 (2013-09-14 21:36:20) TIMER_START{resolveServlet(JcrNodeResource, type=sling:redirect, superType=null, path=/)}
  1 (2013-09-14 21:36:20) TIMER_END{0,resolveServlet(JcrNodeResource, type=sling:redirect, superType=null, path=/)} Using servlet /libs/sling/servlet/default/edit.jsp
  1 (2013-09-14 21:36:20) TIMER_END{0,ServletResolution} URI=/.edit.html handled by Servlet=/libs/sling/servlet/default/edit.jsp
  1 (2013-09-14 21:36:20) LOG Applying Requestfilters
  1 (2013-09-14 21:36:20) LOG Calling filter: org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter
  1 (2013-09-14 21:36:20) LOG Calling filter: org.apache.sling.explorer.post.POSTServletFilter
  1 (2013-09-14 21:36:20) TIMER_START{/libs/sling/servlet/default/edit.jsp#0}
  3 (2013-09-14 21:36:20) LOG Including resource JcrNodeResource, type=sling:redirect, superType=null, path=/ (SlingRequestPathInfo: path='/', selectorString='head', extension='html', suffix='null')
  3 (2013-09-14 21:36:20) TIMER_START{resolveServlet(JcrNodeResource, type=sling:redirect, superType=null, path=/)}
  3 (2013-09-14 21:36:20) TIMER_END{0,resolveServlet(JcrNodeResource, type=sling:redirect, superType=null, path=/)} Using servlet /libs/sling/servlet/default/head.jsp
0(2013-09-1421:36:20)计时器启动{请求处理}
0(2013-09-14 21:36:20)注释计时器结束格式为{,}
0(2013-09-1421:36:20)LOG Method=GET,PathInfo=/.edit.html
0(2013-09-1421:36:20)计时器开始{ResourceResolution}
1(2013-09-14 21:36:20)TIMER_END{1,resourcesolution}URI=/。edit.html解析为Resource=JcrNodeResource,type=sling:redirect,superType=null,path=/
1(2013-09-14 21:36:20)日志资源路径信息:SlingRequestPathInfo:Path='/',selectorString='edit',extension='html',suffix='null'
1(2013-09-1421:36:20)计时器启动{ServletResolution}
1(2013-09-14 21:36:20)计时器启动{resolveServlet(JcrNodeResource,type=sling:redirect,superType=null,path=/)}
1(2013-09-14 21:36:20)计时器{0,使用servlet/libs/sling/servlet/default/edit.jsp解析servlet(JcrNodeResource,type=sling:redirect,superType=null,path=/)}
1(2013-09-14 21:36:20)TIMER_END{0,ServletResolution}URI=/.edit.html由Servlet处理=/libs/sling/Servlet/default/edit.jsp
1(2013-09-1421:36:20)应用请求过滤器的日志
日志调用过滤器:org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter
日志调用过滤器:org.apache.sling.explorer.post.POSTServletFilter
1(2013-09-1421:36:20)计时器启动{/libs/sling/servlet/default/edit.jsp}
3(2013-09-14 21:36:20)日志,包括资源JcrNodeResource,type=sling:redirect,superType=null,path=/(SlingRequestPathInfo:path='/',selectorString='head',extension='html',suffix='null')
3(2013-09-14 21:36:20)计时器启动{resolveServlet(JcrNodeResource,type=sling:redirect,superType=null,path=/)}
3(2013-09-14 21:36:20)计时器{0,使用servlet/libs/sling/servlet/default/head.jsp解析servlet(JcrNodeResource,type=sling:redirect,superType=null,path=/)}

您还可以找到使用服务处理请求的脚本或servlet:


正如@robert_munteanu所示,系统控制台上的“请求”选项卡是跟踪请求处理的最佳位置

这是Sling应用程序中的常见习惯用法。GET/POST请求、包含选择器的请求或具有不同扩展名的请求使用不同的JSP

请看一看,以了解这在高级别上是如何工作的,或者在Sling单元测试中,该测试探索了更广泛的用例

    Servlet servlet = servletResolver.resolveServlet(slingRequest);
    RequestUtil.getServletName(servlet);