mrj*_*per 1 sling aem sightly htl
TLDR:创建一个名为“ mypage.html”的新AEM页面。在URL中提供后缀。将此后缀传递给Sling servlet。后缀用作URL参数。
所需的网址示例:http:// localhost:4502 / mypage.html / john / smith
因此,我创建了一个可以读取后缀的servlet(使用本指南:http : //www.aemcq5tutorials.com/tutorials/sling-servlet-in-aem/)。
@SuppressWarnings("serial")
@SlingServlet(paths="geometrixx/components/hompepage", selectors="name", extensions="html",methods="GET", metatype=true)
public class StaffProfileServlet extends SlingAllMethodsServlet {
private static final Logger log = LoggerFactory.getLogger(CourseBookmarkServlet.class);
@Override
protected void doGet(final SlingHttpServletRequest request,
final SlingHttpServletResponse response) throws ServletException, IOException {
RequestPathInfo rpi = request.getRequestPathInfo();
String[] suffixes = rpi.getSuffix().split("/");
Run Code Online (Sandbox Code Playgroud)
如果我通过http:// localhost:4502 / content / geometrixx / en.name.html / first / last访问它,它将正常工作
接下来,我要创建一个名为“ mypage.html”的新页面,并首先提供后缀作为后缀。
mypage将在格式正确的页面中显示与该人有关的信息。使用上面的代码,我得到的只是JSON响应。
我认为实现我的目标所需的一些假设/更改:
如果我的假设正确,那么如何从HTL / Sightly访问后缀?我知道我可以通过$ {request.requestURI}甚至Javascript获取URI。然后使用此值,可以在我的AJAX调用中使用它。
但这是AEM / Sling的方法吗?还是有更好的方法来做我想做的事?
非常感谢!
您可以使用HTL的RequestPathInfo接口来访问后缀。$ {request.requestPathInfo.suffix}
可以通过HTL-> here访问全局对象。
通过请求对象可访问的方法-> 这里。
| 归档时间: |
|
| 查看次数: |
646 次 |
| 最近记录: |