cuser
cuser

Reputation: 432

Reusing a template page in Spring MVC

What is the best and easiest technology from the followings?

Tiles, velocity or freemaker?

Thank you.

Upvotes: 6

Views: 5382

Answers (1)

BalusC
BalusC

Reputation: 1109112

There's no "best", but it's good to know that JSP as being a view technology already provides the <jsp:include> tag for this. E.g.

<!doctype html>
<html lang="en">
    <head>
        <title>SO question 2158749</title>
    </head>
    <body>
        <jsp:include page="menu.jsp" />
        <h1>Content</h1>
    </body>
</html>

where in you can just code menu.jsp as if it's a part of the parent page:

<ul>
    <li><a href="home">Home</a></li>
    <li><a href="faq">FAQ</a></li>
    <li><a href="content">Content</a></li>
</ul>

There are two "standard" alternatives: the @include directive and the JSTL <c:import> tag.

The difference is that the @include directive includes the page during compile time (thus it will happen only once), while the <jsp:include> includes the page during runtime (which has actually the benefit that you can include another dynamic content).

Further is the difference of <c:import> that it includes the generated output of the page and thus not the source code as both <jsp:include> and @include does. The major benefit of <c:import> is however that you can include external resources this way. E.g.

<c:import url="http://google.com" />

Upvotes: 15

Related Questions