c:import

Yet another way to include content in a JSP page.

We already know:
The include directive, to perform a static inclusion of a file at translation time:
<%@ include file="header.html" %>
The include standard action, to add dinamically content at request time:
<jsp:include page="header.jsp" />

The JSTL tag c:import it is more flexible than the equivalent standard action, we can use it to get content from outside the container:
<c:import url="http://www.wickedlysmart.com/skyler/horse.html" />
As for the standard action, the standard tag could use a param tag to pass a parameter to the included file:
<c:import url="header.jsp" >
<c:param name="subTitle" value="We take the sting out of SOAP." />
</c:import>
The access to the parameter in the included file is done in the same way:
${param.subTitle}
More information on JSTL in chapter nine of Head First Servlet and JSP.

No comments:

Post a Comment