JSP Include Directive

In this tutorial you will learn about the JSP Include Directive and its application with practical example.

JSP Include Directive

The include directive is used to include external files during the translation phase. Translation phase is the phase when JSP page get converted into the equivalent servlet. We can directly add in jsp but we have to write code each JSP page, let’s get understand it by simple example: suppose we have 50 JSP file and we want to add header in each file so write code to each JSP page will be bad idea, we can simply create a header file and then we can include it in each jsp. If we don’t like header color so we will go to header file and simply change the color, it will change in each JSP page. The main purpose of include directive is code re-usability.

Table Of Contents

Syntax:

Example: Let’s get understand it by an simple example. Here I have created two files,

1.header.html

2.index.jsp

 

1.header.html: We will include this file in our index.jsp page. I have created some menus in header file, check below code.

2.index.jsp: It will be our launching page for our Java Web Application and also we will include our header.html file in this jsp page. Check below code.

Output: So we are done with our Include directive coding, run this code you will find output like below image.

1

In this tutorial we have learn about the JSP Include Directive and its application with practical example. I hope you will like this tutorial.