Discussions

Web tier: servlets, JSP, Web frameworks: diff between include directive and tag

  1. diff between include directive and tag (4 messages)

    What is the difference between the include directive and include tag.

    <jsp:include page="hello.jsp"/>


    <%@ include file="hello.jsp" %>

    Syed Imthias Basha
  2. The former (<jsp:include...>) will read in the content of the included file EVERY time the tag is hit.

    The latter will read in the file once, and then leave the content in cache. It will not read that file again unless the web/app server is restarted.

    If the content of the included file is dynamic (changing), then use the first one. If it's static, like a normal html file, you may use the second one.

    Also, you may wish to download the JSP Spec, as it will tell you all sorts of information.

    GMan
  3. This is not quite correct.

    <%@include file=".."%> is actually a pre-processing, pre-compiling directive. I makes the specified file part of your page's source code - and later it will be compiled all this code will be compiled into single servlet class. So this is absolutely equivalent to cut&paste of the code of the included file, and this included file does not mean anything by itself.

    <jsp:include...> preserves separate identities of a target and an included pages. They are compiled separately into 2 different servlets. When execution of target servlets reaches the <jsp:include..> directive its execution is temporarily suspended, and included page is called as if this call came from the outside - but with the same request object as the target page. When the included pages executes its response is included into the response of the target page and its execution resumes.
  4. diff between include directive and tag[ Go to top ]

    Hai folks,

    Can you tell me which one is correct. So that I will update myself.

    Thanx in advance.

    BFN
    VT
  5. The second message is more accurate as to what each of those directives do

    no go update yourself