简体   繁体   中英

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.

WEB-INF directory is a special directory that is not part of the public directory tree of your web (Servlet) application.

The Servlet Specification states (page 70 or so):

A special directory exists within the application hierarchy named “WEB-INF”. This directory contains all things related to the application that aren't in the document root of the application. The WEB-INF node is not part of the public document tree of the application. No file contained in the WEB-INF directory may be served directly to a client by the container. However, the contents of the WEB-INF directory are visible to servlet code using the getResource and getResourceAsStream method calls on the ServletContext , and may be exposed using the RequestDispatcher calls.

AngularJS cannot see any folder inside your web application WEB-INF folder since it has no "connection" to it.

You will have to add those template files in a public folder, view-able by your Angular template files.

Got it. I need to use dynamic include as

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

This is working fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM