title: Templating in JSP. Adding the <script> and <link> tags from different template clients to the <head> tag of the template
body: <p>I am going with templating in JSP as shown below. The tag files given below are stored under <code>/WEB-INF/tags</code>.</p>
  
  <p>genericTag.tag (it is a basic template) :</p>
  
  <pre><code>&lt;%@tag description="put the tag description here" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;%@attribute name="north" fragment="true" %&gt;
  &lt;%@attribute name="south" fragment="true" %&gt;
  &lt;%@attribute name="west" fragment="true" %&gt;
  &lt;%@attribute name="title" required="true" fragment="true"%&gt;
  &lt;%@attribute name="header" fragment="true"%&gt;
  
  &lt;html&gt;
      &lt;head&gt;
          &lt;link href="resources/admin/css/main-template-css.css" rel="stylesheet"/&gt;
          &lt;link rel="stylesheet" href="resources/admin/css/header-menu.css"/&gt;
          &lt;link rel="stylesheet" href="resources/default/css/header-style.css"/&gt;
  
          &lt;script type="text/javascript" src="resources/default/js/jquery-1.8.0.min.js"&gt;
          &lt;/script&gt;
          &lt;script type="text/javascript" src="resources/default/js/template-script.js"&gt;
          &lt;/script&gt;
          &lt;jsp:invoke fragment="header"/&gt;
      &lt;/head&gt;
  
      &lt;title&gt;&lt;jsp:invoke fragment="title"/&gt;&lt;/title&gt;
  
      &lt;body&gt;
          &lt;div id="container" class="clearfix"&gt;
              &lt;div id="north"&gt;
                  &lt;jsp:invoke fragment="north"/&gt;
              &lt;/div&gt;
              &lt;div id="west"&gt;
                  &lt;jsp:invoke fragment="west"/&gt;
              &lt;/div&gt;
              &lt;div id="content"&gt;
                  &lt;jsp:doBody/&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div id="south"&gt;
              &lt;jsp:invoke fragment="south"/&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>template.tag (it is a base template tag that uses genericTag.tag) :</p>
  
  <pre><code>&lt;%@tag description="put the tag description here" pageEncoding="UTF-8"%&gt;
  
  &lt;%@taglib prefix="t" tagdir="/WEB-INF/tags" %&gt;
  &lt;%@attribute name="pageTitle" required="true"%&gt;
  
  &lt;t:genericTag&gt;
      &lt;jsp:attribute name="header"&gt;
          &lt;script type="text/javascript" src="resources/default/js/template-scriptsss.js"&gt;
          &lt;/script&gt;
      &lt;/jsp:attribute&gt;
  
      &lt;jsp:attribute name="title"&gt;${pageTitle}&lt;/jsp:attribute&gt;
  
      &lt;jsp:attribute name="north"&gt;
          &lt;jsp:include page="/WEB-INF/admin_template_files/North.jsp" flush="false"/&gt;
      &lt;/jsp:attribute&gt;
  
      &lt;jsp:attribute name="west"&gt;
          &lt;jsp:include page="/WEB-INF/admin_template_files/West.jsp" flush="false"/&gt;
  
      &lt;/jsp:attribute&gt;
  
      &lt;jsp:attribute name="south"&gt;
          &lt;jsp:include page="/WEB-INF/admin_template_files/South.jsp" flush="false"/&gt;
      &lt;/jsp:attribute&gt;
  
      &lt;jsp:body&gt;
          &lt;jsp:doBody/&gt;
      &lt;/jsp:body&gt;
  &lt;/t:genericTag&gt;
  </code></pre>
  
  <p>And finally any template client (Test.jsp) that uses the said template looks like the following.</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;%@taglib prefix="t" tagdir="/WEB-INF/tags" %&gt;
  
  &lt;t:template pageTitle="Test"&gt;
    &lt;p&gt;
          Contents of the tag body go here.
    &lt;/p&gt;
  &lt;/t:template&gt;
  </code></pre>
  
  <hr>
  
  <p>This goes all fine. Now, I need to add some JavaScript/CSS files (<code>&lt;script src="path/to/jsFile"&gt;</code>, <code>&lt;link href="path/to/cssFile"&gt;</code>) from different template clients as and when required.</p>
  
  <p>Using a <code>&lt;jsp:attribute&gt;</code> such as the one shown in the template.tag file like <code>&lt;jsp:attribute name="header"&gt;</code> adds JavaScript/CSS files to the <code>&lt;head&gt;</code> tag of the template but this is fixed. They need to be added from different template clients randomly. It is not fixed which client may or may not add them when is fully transparently dependent upon the functional requirements.</p>
  
  <p>Can this somehow be made possible to add (import) JavaScript/CSS files to the <code>&lt;head&gt;</code> tag of the template <strong>from a given template client</strong>? (Currently, they are being added from the base template tag - template.tag. It is fixed, not flexible and not reusable across different template clients).</p>
  
  <hr>
  
  <p>I am using an attribute <code>pageTitle</code> with the <code>&lt;t:template&gt;</code> tag which supplies the value/text of the <code>&lt;title&gt;</code> tag of the template.</p>
  
  <p>Does JSP provide some facility as Facelets does such as (on the template)</p>
  
  <pre><code>&lt;title&gt;&lt;ui:insert name="title"&gt;Default Title&lt;/ui:insert&gt;&lt;/title&gt;
  </code></pre>
  
  <p>and this default value of the <code>&lt;title&gt;</code> tag can then be overridden from a template client such as</p>
  
  <pre><code>&lt;ui:define name="title"&gt;New Page Title&lt;/ui:define&gt;
  </code></pre>
  
  <p>?</p>