Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Can "jsp:include" be used in CQ 5?

Avatar

Level 7

In a template file, I have a chunk code of like this:

<jsp:include page="/apps/acme/components/menu/menu-items.jsp"> <jsp:param name="menuItem" value="${rootItem}" /> </jsp:include>

menu-items.jsp recursively includes itself like:

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <li> ${menuItem.title} <c:if test="${fn:length(menuItem.children) > 0}"> <ul> <c:forEach var="child" items="${menuItem.children}"> <jsp:include page="/apps/acme/components/menu/menu-items.jsp"> <jsp:param name="menuItem" value="${child}"/> </jsp:include> </c:forEach> </ul> </c:if> </li>

However CQ encounters an error rendering this:

Caused by: org.apache.sling.api.resource.ResourceNotFoundException: No resource found

I am using jsp:include rather than cq:include because I want to pass a parameter to the script, and as the script is invoked recursively each time with a different value for its parameter I prefer not to use request attributes and manually manage the parameter stack.

However this doesn't seem to work. Is it allowed to use jsp:include in CQ5? Am I missing something here?

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Employee

Yes, you can use jsp:include in CQ5/AEM, but it doesn't do what you think it does. jsp:include, per specification, goes all the way back to the RequestDispatcher. So you can include smoething like /content/geometrixx/en.html (and even add parameters), but you can't directly include a JSP.

View solution in original post

3 Replies

Avatar

Correct answer by
Employee

Yes, you can use jsp:include in CQ5/AEM, but it doesn't do what you think it does. jsp:include, per specification, goes all the way back to the RequestDispatcher. So you can include smoething like /content/geometrixx/en.html (and even add parameters), but you can't directly include a JSP.

Avatar

Level 7

Thanks for the reply Justin.

So other than the cq:include/request attributes combo is there any other way to include a JSP page and pass parameters to it?

Avatar

Employee

LinearGradient wrote...

So other than the cq:include/request attributes combo is there any other way to include a JSP page and pass parameters to it?

 

See, that's the thing. In CQ/AEM, JSPs aren't "pages" (yes I know that the P in JSP is "Pages"), they are really scripts which need a resource to execute against.

What you can do, although I don't know if this meets your needs, is to create a resource (could be a synthetic resource provided by a ResourceProvider or a real JCR Node) which has the appropriate sling:resourceType and then use jsp:include.

However, I think your problem (at least as I understand it), could be handled in a more idiomatic way simply by using resource inclusion.