include action and include directive


Web tier: servlets, JSP, Web frameworks: include action and include directive

  1. Hi,
       In JSP there are two ways to include files either
    using include action or using include directive.
    when is it appropriate to use the action and
    when to use the directive?
    Any ideas?
    Thanks in advance
  2. There are two ways to include a file

    - Including Files at Page Translation Time
    - Including Filis at Request Time

    <%@ include...> directives is used to include a file in the main jsp document at the time the document is translated into servlet. Since you can include a file containing the JSP code not only HTML. But if the include file is changed, all the files that use it, needs to be updated.

    <jsp:include...> action includes files at the time of the user request and thus you are not required to update the main file when any changes is done in the include files. Although the include files cannot contain JSP.

    when to use what: Use include directive if include files will use JSP code. otherwise use jsp:include action.

  3. What if we have a javascript function in the included html or jsp file? should we use include action or directive.