title: JSP + JavaScript: templating
body: <p>I have a server-side HTML templating with JSP + JSTL, which generates, say, a table with some user data:</p>
  
  <pre><code>&lt;body&gt;
      ...
      &lt;table&gt;
          &lt;c:forEach items="${users}" var="user"&gt;
          &lt;tr&gt;
              &lt;td&gt;${user.name}&lt;/td&gt;
              &lt;td&gt;${user.age}&lt;/td&gt;
              &lt;td&gt;${user.department}&lt;/td&gt;
          &lt;/tr&gt;
          &lt;/c:forEach&gt;
      &lt;/table&gt;
      ...
  &lt;/body&gt;
  </code></pre>
  
  <p>This is a template number 1.</p>
  
  <p>The user can submit new data to the server through the form. The data is sent by AJAX, and upon successfull request it should be dynamically appended to the table without any page reload. </p>
  
  <p>To append the data, I need to use a template number 2, which is encapsulated inside JavaScript or is present at the HTML page with "display: none;" and "class='template'".</p>
  
  <pre><code>&lt;tr class="template" style="display: none;"&gt;
      &lt;td&gt;%user.name%&lt;/td&gt;
      &lt;td&gt;%user.age%&lt;/td&gt;
      ...
  &lt;/tr&gt;
  ...
  &lt;script&gt;
      $(".template").clone().fillTheTemplateAndAppendToTheTable(user); //just to explain
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>The question</strong>: can I avoid HTML code duplication and have only one single template in this case? If yes, how to do that?</p>