What is the best way to create JSP layout template? [duplicate]

Put the following in WEB-INF/tags/genericpage.tag

<%@tag description="Overall Page template" pageEncoding="UTF-8"%>
<%@attribute name="header" fragment="true" %>
<%@attribute name="footer" fragment="true" %>
    <div id="pageheader">
      <jsp:invoke fragment="header"/>
    <div id="body">
    <div id="pagefooter">
      <jsp:invoke fragment="footer"/>

To use this:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags" %>

    <jsp:attribute name="header">
    <jsp:attribute name="footer">
      <p id="copyright">Copyright 1927, Future Bits When There Be Bits Inc.</p>
        <p>Hi I'm the heart of the message</p>

That does exactly what you think it does!

This was part of a great answer by Will Hartung on this link.

Leave a Comment