[ Team LiB ] Previous Section Next Section

The include Directive

Many programmers who come from the C and C++ worlds are disappointed with the lack of an include keyword in Java. The include directive in JSP performs the same service that the C include keyword does: It includes a file at compile time as opposed to runtime.

The nice thing about including a file at compile time is that it requires less overhead than a file included at runtime. The included file doesn't need to be a servlet or JSP, either. When the JSP compiler sees an include directive, it reads the included file as if it were part of the JSP that's being compiled.

You might have a standard HTML header that you want to put on all your files. For example, to include a file named header.html, your include directive would look like this:

<%@ include file="header.html" %>

The filename in the include directive is actually a relative URL. If you just specify a filename with no associated path, the JSP compiler assumes that the file is in the same directory as your JSP, as in the example with header.html.

    [ Team LiB ] Previous Section Next Section