Jsp include directive

Whenever we run a jsp on the container, the jsp get converts into servlet code i.e. a java source code.

Jsp include directive

Jsp include directive

        

Whenever we run a jsp on the container, the jsp get converts into servlet code i.e. a java source code. Then this servlet is compiled and .class file is generated. This is known as translation time. Then this .class file is called is again and again whenever the request comes for the jsp page. When the jsp page is firstly compiled it takes some time to be compiled. So whenever we want to add a static content or that content which doesn't need to be changed frequently then we should keep it inside the directive tag. 

In Jsp we have provided the facility to include a particular file. By using the include tag the file will be included in the jsp page at the translation time. In this example we have created a jsp file which has to be included in the other jsp file by using the tag <%@ include file = " "%>, this tag is  known as a include directive tag which will include the file in the jsp file at the translation time. This tag is mostly used to include the static content which doesn't need to be changed frequently. So, remember whenever we need to include a static file which doesn't need to be changed then we should prefer the include directive tag <%@ include file = " /"%> 

The code of the program is given below:

 

<html><head>
<title>Use of include tag in Jsp</title>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#D90046">
  <tr>
    <td width="25%">
      <p align="center"><font color="White">Home</font></td>
    <td width="25%">
      <p align="center"><font color="White">Register</font></td>
    <td width="25%">
      <p align="center"><font color="White">Login</font></td>
    <td width="25%">
      <p align="center"><font color="White">About Us</font></td>
  </tr>
</table>
</body>
</html>

 

<html>
<title>Use of include tag in Jsp</title>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#FFFFFF">
  <tr>
    <td width="100%">
      <p align="center">Copyright &#169 2007 All rights are Reserved</td>
  </tr>
</table>
</body>
</html>

 

<%@ include file="header.jsp" %>
<TABLE align="center" border= "0" bgcolor="#FFFFFF" height="50%" weight="25%">
<TR>
	<TD>This Page Include Header.jsp and Footer.jsp
	</TD>
</TR>
</TABLE>
<%@ include file="footer.jsp" %>

The output of the program is given below:

Download this example.