SCWCD exam
SCWCD FAQ
Other SCWCD sites
SCWCD Books
About Java Prepare
Questions
DD
JSP
Taglibs
Servlets
EL and JSTL
JSP Tutorial
Page Directive
Include Directive
Taglib Directive
Declaration
Scriptlet
Expression
Implicit Objects
Comments
Action
Advertisements

javaprepare: JSP tutorial - Include directive
SCWCD home | SCWCD questions | SCWCD links | SCJP home

javaprepare.com:JSP tutorial - Include directive

SCWCD home | SCWCD questions | SCWCD links | SCJP home
Most web applications have contents that is included in many pages. These type of reusable contents can be put in a page fragment, and that page fragment can be included the top level pages. This functionality is supported using the include directive of JSP.

Lets say you have a common left navbar across all pages of the web application. The navbar can be created in a file navbar.jspf. The extension jspf is used here for fragment as a good practise (using jsp extension also works fine). The main file can then include the nav bar using the include directive as shown below.

<%@include file="navbar.jspf%>
JSP page will behave as if the contents of navbar were defined in the main page. The XML compatible syntax for the include directive is -
<jsp:directive.include file="pageFragmentURL"/>