A JSP can embed one or more child pages. The embedded page can be one of two types:

The DSP library also provides tags for embedding other HTML elements, such as frames (dsp:frame) and images (dsp:img).

JSP Fragments

A simple header that contains static elements can be stored as a JSP fragment (JSPF). The JSP include directive inserts the fragment into the parent page so it is processed as part of the parent page. For example:

<%@include file="header.jspf"%>

Dynamic elements in the child fragment can access values provided by the parent page, excluding those elements that are constrained to page or request scope. All URLs in header.jspf, including the calling URL (file="header.jspf") resolve relative to the parent page. If the child page should resolve its URLs relative to itself, consider including it by calling dsp:include.

JSPs

A JSP can embed another JSP by calling dsp:include or jsp:include. In both cases, the page compiler processes the child page before inserting it into the parent page. The embedded page must be a self-sufficient JSP with all required tags, including dsp:page. For example:

<dsp:include page="RegistrationForm.jsp" flush="true"/>

dsp:include offers these benefits over jsp:include:

  • It can pass page parameters from the parent page to the child page, including dynamic objects.

  • Its page attribute lets you set absolute URLs. See Absolute URLs for more information.

  • URLs resolve relative to the current page, which removes the burden of managing URL paths in descendant pages.

Note: Always use dsp:include to embed a page that uses runtime expressions.

 
loading table of contents...