- The <c:import> tag imports a resource specified by a URL and exposes it to the page, variable, or reader.
- 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.
- <c:import> is similar to the <jsp:include> directive, but with more features.
- The body of the import tag can have param tags for adding parameters to the URL.
- we can overcome jsp:include limitations with the JSTL import tag.
- The import tag adds functionality to the jsp:include tag and eliminates the need to code these functions yourself.
- 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”/> - You can even use ftp:
<c:import url=”ftp://ftp.example.com/somecontent.txt”/> - 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. - 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.
- 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>
Filed under: JSP
good page need more explanation for [varReader=”variable name”]
Hi! nice site!
Excellent article
Easily to understood concept
Good Page with nice explainations.. Still more details will be highly appreciated and welcomed!
Great, thanks!