Java Reference
In-Depth Information
included file contains snippets of Java code, they will be part of the resulting
program. For example, you could define a variable in the included file and
reference in the including file.
Also, since this inclusion happens at compile time, if you later change the
included file, the change will not become visible until the JSP files that do the
including are recompiled. (On Linux, this is simply a matter of touch ing all
the JSP, as in:
$ touch *.jsp
assuming all your JSP files are in that directory. Touching them updates their
time of last modification, so the Web server thinks they've been modified so
the next access will cause them to be reconverted and their generated servlets
reloaded. You get the idea.
There is another way to do an include in JSP—one that happens not at
compile time, but at runtime. The syntax is different than the directives we've
seen so far, but more on that in minute. First, an example of this kind
of include:
<jsp:include page="URL" flush="true" />
In this format, the page specified by the URL (relative to this Web appli-
cation's root) is visited and its output is included in place amongst the output
of this JSP, the one doing the include.
A few quick notes:
• Be sure to include the ending “ / ” in the directive; it's part of the XML
syntax which is a shorthand for ending the element in the same tag as you
begin—that is, <p /> instead of <p> </p> .
• When all is working, flush being true or false doesn't matter; when
the included page has an error, then flush="true" causes the output to
the browser to end at the point of the include; with flush="false" , the
rest of the page will come out despite the error in the include.
• The page that is being included is turned into its own servlet. That is, it
is its own JSP. You don't have to just include static HTML, you can
include a JSP.
• Since this is a runtime include, all you are including is the output of that
other page. You can't, with this mechanism, include Java snippets or
declarations, but only HTML output.
Search WWH ::




Custom Search