Sunday, March 30, 2008

VS

<jsp:include>VS <c:import>       

  1. The <c:import> tag imports a resource specified by a URL and exposes it to the page, variable, or reader.
  2. The <jsp:include> standard action is a request-time action that will include the output of another JSP at the location of the tag within the calling JSP.
  3. The body of the import tag can have param tags for adding parameters to the URL.
  4. The first additional function allows you to include content directly from other Web sites. So the following is now legal:
    <c:import url=”http://www.example.com/somecontent.html”/>
  5. You can even use ftp:
    <c:import url=”ftp://ftp.example.com/somecontent.txt”/>
  6. Rather than dump an imported URL straight to the page, you can store it in a variable. This is a common strategy in all the JSTL tags and increases the power of a JSP page:
    <c:import url=”http://www.example.com/example.inc” var=”example”/> Once this included page is stored in the example variable, you can use another taglib, such as the Jakarta String taglib, to replace all references to example.com with done.com.
  7. Since you can store <c:import> in a variable <c:import> might do some type of full read before printing to output, whereas <jsp:include> uses buffering. This could show a performance difference for very large files, with <c:import> requiring longer and taking more memory to get all the data in the import whereas <jsp:include> did things with buffers.

Import Syntax:

<c:import url=”resource URL”
          [var=”variable name”]
          [scope=”page|request|session|application”]
          [varReader=”variable name”]
          [context=”context name”]
          [charEncoding=”character encoding”]>
     JSP body content
</c:import>

Include Syntax:

<jsp:include page=”…url..” flush=”true or false“/>

The tag can optionally contain a body:

<jsp:include page="…url…” flush=”true or false“>
  <jsp:param  …./>
</jsp:include>

 

Summary:

If you want to include a page within webapplication, go for JSP:include

If you want to include a page outside webapplication, go for JSTL import

No comments:

Post a Comment