JSP DIRECTIVES
Basically JSP have 3 type of directives :- Page Directives
- Include Directive
- Taglib Directive
Include directive provide us the facility to reuse the elements.
* Included elements can contain jsp code so they are inserted into the the page at the time the page is translated to servlet.
So the main problem with include directive is if we modify the included page content, we have to update the all the main jsp pages that include that page .
There is a another way to overcome this limitation.
How to include file at Page Translation Time with Include Directive
Syntax <% include file = "relative url" %>
Example :
there are 2 files : IncludeDirective.jsp : this page is included into other jsp page.
IncludeDirective2.jsp : Main Jsp page that include IncludeDirective.jsp page.
IncludeDirective.jsp :
<%-- this page will be included into other jsp page --%>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<%@ page import="java.util.Date" %>
<%!
private int accessCount = 1;
private Date accessDate = new Date();
private String accessHost = "<I>No previous access</I>";
%>
<P>
<HR>
This page © 2000
<A HREF="http//www.my-company.com/">my-company.com</A>.
This page has been accessed <%= ++accessCount %>
times since server reboot. It was last accessed from
<%= accessHost %> at <%= accessDate %>.
<% accessHost = request.getRemoteHost(); %>
<%= request.getContentType() %>
<% accessDate = new Date(); %>
</body>
</html>
IncludeDirective2.jsp
<%-- the main jsp page which will include other jsp --%>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<P>
Information about our products and services.
<P>
Blah, blah, blah.
<P>
Yadda, yadda, yadda.
<%-- this file will be included at the time of translation of jsp page into servlet --%>
<%@ include file="IncludeDirective.jsp" %>
</body>
</html>
Output :