java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to include a page fragment into JSP?

In this example you can learn how to include a JSP fragment into another JSP page. This is a common practice when creating a web application where we usually have a navigation section, the main content and the footer of a web page.

Using the include directive make it simpler to maintain the fragment of a web page, which mean that when we need to change the footer section we just need to alter the footer include file and all the page that includes it will get the benefit.

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <title>Webapp Include Demo</title>

<div id="header">
    <%@ include file="/common/header.jspf" %>

<div id="content">
    <p>Main application content goes here!</p>    

<div id="footer">
    <%@ include file="/common/footer.jspf" %>