Include

Includes the contents of another file. The file is included dynamically (at page run time) so if the file to be included is modified, the modifications are seen instantly.

Internally, a servlet RequestDispatcher is used to include the file. If a included file name is absolute (begins with a '/'), then it is relative to the servlet webapp, otherwiser it is relative to the current page.

Any molly declarations and code are ignored in the included file. (see include-file and include-decl for alternatives).

You can however, send additional parameters to the included page even when using dynamic includes.

The RequestDispatcher (used to dynamically include the file) is obtained from the HttpServletRequest. As of writing (Servlet 2.5), this means additional parameters attached to the include file URL are ignored by the servlet engine.
[include "file.mp?greeting=hello"]
The included file (file.mp in this example) will return null for request.getParameter("greeting"). The fix for this is:
[[ req.setAttribute("greeting", "hello"); ]]
[include "file.mp"]
Now, in the included file (file.mp), one can say request.getAttribute("greeting") and this will return hello.

Syntax

Include sections can appear anywhere in text sections.
[include filename]
Quotes around the filename are optional.

The name of the included file can contain expressions and hence be generated dynamically. For example:

[[ int i = 3; ]]
[include 'foo[=i].html' ]
will include a file called foo3.html in the page.

Tag-Escape

To prevent the tag from being recognized, this tag can be escaped by prefixing the start tag with a backslash: \[include

Example

An simple example of a conditional include (for illustrative purposes only). <html> <body> [[ String include_file_name = req.getParameter("name") + ".header"; ]] [include '[=include_file_name]' ] </body> </html> this is the admin.header this is the user.header