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 ""]
The included file ( in this example) will return null for request.getParameter("greeting"). The fix for this is:
[[ req.setAttribute("greeting", "hello"); ]]
[include ""]
Now, in the included file (, one can say request.getAttribute("greeting") and this will return hello.


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.


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


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