Including Files at Page
Translation Time
Format
<%@ include file="Relative URL" %>
Purpose
To reuse JSP content in multiple pages,
where JSP content affects main page
Notes
Servers are not required to detect changes to the included
file, and in practice many don t
Thus, you need to change the JSP files whenever the
included file changes
You can use OS specific mechanisms such as the Unix
"touch" command, or
<% Navbar.jsp modified 3/1/02 %>
<%@ include file="Navbar.jsp" %>
51
JSP
www.corewebprogramming.com
Reusable JSP Content:
ContactSection.jsp
<%@ page import="java.util.Date" %>
<% The following become fields in each servlet that
results from a JSP page that includes this file. %>
<%!
private int accessCount = 0;
private Date accessDate = new Date();
private String accessHost = "No previous access";
%>
This page © 2000
my company.com.
This page has been accessed <%= ++accessCount %>
times since server reboot. It was last accessed from
<%= accessHost %> at <%= accessDate %>.
<% accessHost = request.getRemoteHost(); %>
<% accessDate = new Date(); %>
52
JSP
www.corewebprogramming.com
26