40. What is the difference between <jsp:include> and <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. <c:import> is similar to the <jsp:include> directive, but with more features.
  4. The body of the import tag can have param tags for adding parameters to the URL.
  5. we can overcome jsp:include limitations with the JSTL import tag.
  6. The import tag adds functionality to the jsp:include tag and eliminates the need to code these functions yourself.
  7. 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”/>
  8. You can even use ftp:
    <c:import url=”
    ftp://ftp.example.com/somecontent.txt”/>
  9. 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.
  10. Since you can store <c:import> in a variable I’m wondering if <c:import> might do some type of full read before printing to output, whereas I imagine <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.
  11. 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>

          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>

About these ads

6 Responses

  1. good page need more explanation for [varReader=”variable name”]

  2. Hi! nice site!

  3. Excellent article

  4. Easily to understood concept

  5. Good Page with nice explainations.. Still more details will be highly appreciated and welcomed!

  6. Great, thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: