Not able to include ftl in jsp

1.2k Views Asked by At

I want to include ftl template in jsp page. How can I achieve it?

details.ftl

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div class="page-content-wrapper">
    <div class="page-content">
        <div class="col-md-12 col-sm-12">
            <div class="portlet yellow-crusta box">
                <div class="portlet-title">
                    <div class="caption">
                        <i class="fa fa-cogs"></i>${entityType} Details
                    </div>
                    <div class="actions">
                        <a href="javascript:;" class="btn btn-default btn-sm">
                            <i class="fa fa-pencil"></i> Edit </a>
                    </div>
                </div>
                <div class="portlet-body">
                    <#list detailsMap?keys as key>
                    <div class="row static-info">
                        <div class="col-md-5 name">
                            ${key}
                        </div>
                        <div class="col-md-7 value">
                            : ${detailsMap[key]}
                        </div>
                    </div>
                    </#list>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

myPage.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page session="false" %>
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<jsp:include page="sidebar.jsp"/>
<jsp:include page="details.ftl"/>
<body>
1

There are 1 best solutions below

0
On

For that the ftl file has to have a visitable URL (though not visitable from outside for security), similarly as jsp-s have. One way of doing that is by using the FreemarkerSerlvet (see http://freemarker.org/docs/pgui_misc_servlet.html). Another question you have to find answer for is if what will provide the data-model. In the case of FreemarkerSerlvet, the data-model is from the attributes of the Servlet request, session, and application context.