Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Jsp Simple-jsp-example Jsp include directive

Related Tutorials


 
 

Share on Google+Share on Google+

Jsp include directive

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

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.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 9, 2008

Related Tutorials

Discuss: Jsp include directive  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Aby
June 24, 2011
include JSP in Servlets

If a JSP is having include directive with aother JSP. Then how the translated Servlet looks. Will is genrate 2 servlets? If so how the main servlet include the other servlet?
DMCA.com