Java Reference
In-Depth Information
Table 3-20. <c:import> Attributes
Name
Type
Description
url
String
URL of the resource to import.
context
String
Name of the context when accessing a relative URL resource that belongs to a
foreign context.
var
String
Name of the exported scoped variable for the resource's content.
scope
Scope for var .
String
charEncoding
String
Character encoding of the content at the input resource.
varReader
String
Name of the exported scoped variable for the resource's content.
In the previous chapter, we saw how the <jsp:include> action lets us encapsulate functionality
in one JSP page and include it in another; for example, you could include a header and footer as
illustrated in Listing 3-49.
Listing 3-49. Using the <jsp:include> Action
<body>
<jsp:include page='/WEB-INF/jsp/header.jsp'/>
<%-- content -%>
<jsp:include page='/WEB-INF/jsp/footer.jsp'/>
</body>
The <jsp:include> action is limited to including the resource that belongs to the same web
application as the including page and specified as a relative URL.
You can use <c:import> instead of <jsp:include> to import resources in the same web application;
Listing 3-50 illustrates how to use <c:import> instead of <jsp:include> .
Listing 3-50. Using <c:import>
<body>
<c:import url='/WEB-INF/jsp/header.jsp'/>
<%-- content --%>
<c:import url='/WEB-INF/jsp/footer.jsp'/>
</body>
With the <c:import> action, other than accessing resources in the same web application, you can
also access external resources or resources in a foreign context. To access an external resource,
you specify an absolute URL for the url attribute, and to access a resource in a foreign context,
you specify a value for the context attribute that represents a context path for the foreign context
along with the url attribute, which represents a context-relative path to the resource. Listing 3-51
illustrates how to use the <c:import> action to import a resource from a foreign context.
Listing 3-51. Importing a Resource from a Foreign Context
<c:import url='/jsp/book.jsp' context='/foreigncontext'/>
 
 
Search WWH ::




Custom Search