title: Importing CSS in JSP tags
body: <p>What are some ways (if any) to link or import a style sheet from a JSP tag called in the &lt;body&gt;? It would be great if I can encapsulate all necessary imports in the JSP tag.</p>
  
  <h3>Current State</h3>
  
  <p><strong>index.jsp:</strong></p>
  
  <pre><code>&lt;%@ page contentType="text/html; charset=utf-8" %&gt;
  &lt;%@ taglib prefix="x" tagdir="/WEB-INF/tags" %&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;!-- we have to know what css file somecontent uses and include it here --&gt;
          &lt;!-- the tag below prints &lt;link rel="/somecontent.css"... /&gt; but makes sure this url is only included once --&gt;
          &lt;x:requireOnce loc="/somecontent.css" type="css" /&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;x:somecontent /&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <h3>Goal</h3>
  
  <p><strong>index.jsp:</strong></p>
  
  <pre><code>&lt;%@ page contentType="text/html; charset=utf-8" %&gt;
  &lt;%@ taglib prefix="x" tagdir="/WEB-INF/tags" %&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;%-- nothing for somecontent tag here --%&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;x:somecontent /&gt;
          ...
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>somecontent.tag:</strong></p>
  
  <pre><code>&lt;%@ tag description="some independent content" %&gt;
  &lt;%@ taglib prefix="x" tagdir="/WEB-INF/tags" %&gt;
  &lt;%-- the inline attribute will indicate that it is in the body and shouldn't use &lt;link&gt; which won't work here --%&gt;
  &lt;x:requireOnce loc="/somecontent.css" type="css" inline="true" /&gt;
  &lt;%-- this will print &lt;script type="text/javascript" src="/somecontent.js" ...&gt;&lt;/script&gt; --%&gt;
  &lt;x:requireOnce loc="/somecontent.js" type="js" /&gt;
  ...
  </code></pre>
  
  <p>Is there a way to keep a reference to the position in the head tag within the JspWriter and insert content there when necessary, i.e. new link tags?</p>
  
  <p>Ideally, I don't want to inline the contents of the stylesheet or use javascript to include the style sheet. Hopefully there's some way with @import, &lt;link&gt; or some JSP magic... Thoughts?</p>