javaangularjsjsptaglibangularjs-ng-template

Custom JSP Tag which include another JSP


I want to create a custom JSP tag as follows.

<ng:template src="../js/Rule/templates/rule-list.jsp" />

Which will actually include the file "../js/Rule/templates/rule-list.jsp" inside a scripts tag and generate HTML as follows.

<script type="text/ng-template" id="../js/Rule/templates/rule-list.jsp">
    Content of ../js/Rule/templates/rule-list.jsp file
</script>

So far I have creates following tagfile.

<%@ attribute name="src" required="true" rtexprvalue="true" %>
<script type="text/ng-template" id="${src}">
    <%@ include file="${src}" %>
</script>

Which is giving this error

File "${src}" not found

Means its trying to include the ${src} instated of its value. Can any one suggest how to include file in tag file from specified attribute value?

Note: I am using angularjs. I want to load angularjs templates without ajax call. Because my browser is not able to load ng-template with AJAX call for cross domain call problem.


Solution

  • Got it. I need to use dynamic include as

    <jsp:include page="${src}" />
    

    This is working fine.