13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

19.3 How to Write a JSP <str<strong>on</strong>g>Applicati<strong>on</strong></str<strong>on</strong>g>433included file c<strong>on</strong>tains snippets of Java code, they will be part of the resultingprogram. For example, you could define a variable in the included file andreference in the including file.Also, since this inclusi<strong>on</strong> happens at compile time, if you later change theincluded file, the change will not become visible until the JSP files that do theincluding are recompiled. (On <strong>Linux</strong>, this is simply a matter of touching allthe JSP, as in:$ touch *.jspassuming all your JSP files are in that directory. Touching them updates theirtime of last modificati<strong>on</strong>, so the Web server thinks they’ve been modified sothe next access will cause them to be rec<strong>on</strong>verted and their generated servletsreloaded. You get the idea.There is another way to do an include in JSP—<strong>on</strong>e that happens not atcompile time, but at runtime. The syntax is different than the directives we’veseen so far, but more <strong>on</strong> that in minute. First, an example of this kindof include:In this format, the page specified by the URL (relative to this Web applicati<strong>on</strong>’sroot) is visited and its output is included in place am<strong>on</strong>gst the outputof this JSP, the <strong>on</strong>e doing the include.A few quick notes:• Be sure to include the ending “/” in the directive; it’s part of the XMLsyntax which is a shorthand for ending the element in the same tag as youbegin—that is, instead of .• When all is working, flush being true or false doesn’t matter; whenthe included page has an error, then flush="true" causes the output tothe browser to end at the point of the include; with flush="false", therest 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, itis its own JSP. You d<strong>on</strong>’t have to just include static HTML, you caninclude a JSP.• Since this is a runtime include, all you are including is the output of thatother page. You can’t, with this mechanism, include Java snippets ordeclarati<strong>on</strong>s, but <strong>on</strong>ly HTML output.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!