JSP Include Directive


In JSP Include Directive,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”/>


Like it? Please Spread the word!