Adobe created Sightly to separate the view from the logic of dynamic HTML. JSP can do the same, but it does not enforce the separation. Sightly does.
Within Apache Sling, logic can be in separate JSP files from the view. The view will use the sling:include tag to incorporate them or the JSP import. In AEM/CQ5, an additional cq:include tag can be used.
Another way to allow design-based JPSP to be design-based and code-based files to be code-base and to keep them apart is through the use of custom JSP tags. With custom JSP tags, the logic can be contained in Java classes that are called when the JSP tags are processed.
Although Apache Sling and Adobe Experience Manager are repository-based, extended JSP tags can be added.
Scott Macdonald of Adobe provided a link in his blog, Scott’s Digital Community, to a tutorial from Adobe CQ Help. This tutorial walks step-by-step through the process of creating custom JSP tags within the Apache Sling and Adobe Experience Manager environment. Adobe CQ Help | Creating Custom Tag Libraries for Adobe Experience Manager