Use templates to standardize layout

Templates are commonly used to enforce a uniform appearance across a set of related pages - often even for an entire web site.

If using JSPs, templates can be easily implemented using either the <@include> directive or the <jsp:include> action.


Here, a template JSP defines the layout. It includes a header, footer, and navigation links. A <jsp:include> inserts the main content or "body" of the page. There are two parameters to the template, which are passed in as request parameters : The <tags:xxx/> items refer to .tag files, that contain small JSP snippets.
<%@ include file="/JspHeader.jsp" %>
<!doctype html>
<html lang='en'>
 <meta http-equiv="Content-Type" content="text/html; charset=uTF-8">
 <%-- TTitle is a request parameter for the templated page title. --%>
  Fish and Chips Club - ${param.TTitle} </title>
 <link rel="stylesheet" type="text/css" href="../../stylesheet.css" media="all">

<div align="center">
 <img class="no-margin" src="../../images/logo.jpg" alt="Fish And Chips Club">

<div class="header">
 "The Total Fish & Chips Dining Experience"

<div class="menu-bar">
 <w:highlightCurrentPage styleClass='highlight'>
  <c:url value="/main/home/" var="homeURL"/> 
  <A href='${homeURL}'>Home</a>
  <c:url value="/main/rsvp/" var="showRsvpURL"/> 
  <A href='${showRsvpURL}'>Rsvp</a>
  <c:url value="/all/logoff/" var="logoffURL"/> 
  <A href='${logoffURL}'>Log Off</a>

<%-- Display error and information messages. --%>

<%-- TBody is a request parameter for the templated page body. --%>
<div class="body">
 <c:if test="${not empty param.TBody}">
  <jsp:include page='${param.TBody}' flush="true"/>
 <c:if test="${empty param.TBody}">
  <jsp:include page="Error.jsp" flush="true"/>



See Also :
Always maintain HttpSessions
Prefer JSTL tags
Prevent self linking
A Web App Framework WEB4J