Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the difference between including files with JSP include directive, JSP include action and using JSP Tag Files?
    primarykey
    data
    text
    <p>It seems that there are two methods for templating with JSP. Including files with one of these statements </p> <pre><code>&lt;%@ include file="foo.html" %&gt; &lt;jsp:include page="foo.html" /&gt; </code></pre> <p>or using JSP tag files </p> <pre><code>// Save this as mytag.tag &lt;%@ tag description="Description" pageEncoding="UTF-8"%&gt; &lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;jsp:doBody/&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And in another JSP page call it with</p> <pre><code>&lt;%@ taglib prefix="t" tagdir="/WEB-INF/tags" %&gt; &lt;t:mytag&gt; &lt;h1&gt;Hello World&lt;/h1&gt; &lt;/t:mytag&gt; </code></pre> <p>So which method should I use? Is one now considered deprecated or are they both valid and cover different use cases?</p> <p><strong>Edit</strong></p> <p>Isn't using this tag file the same as using an include?</p> <pre><code>// Save this as product.tag &lt;%@ tag description="Product templage" pageEncoding="UTF-8"%&gt; &lt;%@ tag import="com.myapp.Product" %&gt; &lt;%@ attribute name="product" required="true" type="com.myapp.Product"%&gt; Product name: ${product.name} &lt;br/&gt; Quantity: ${product.quantity} &lt;br/&gt; </code></pre> <p>And call it on another JSP with</p> <pre><code>&lt;%@ taglib prefix="t" tagdir="/WEB-INF/tags" %&gt; &lt;t:product&gt; &lt;c:forEach items="${cart.products}" var="product"&gt; &lt;t:product product="${product}"/&gt; &lt;/c:forEach&gt; &lt;/t:product&gt; </code></pre> <p>That seems to me to be the very same as using an include and passing parameters to it. So are Tag Files the same as includes?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload