Friday, March 06, 2009

Jsp Include directive vs action

Jsp Include directive
At JSP page translation phase, the content of the file mentioned in the include directive is included/added as it is, in the place where the directive is used. Then the total JSP page is translated into a java servlet class. The included file is a static resource like html or a JSP page. Generally JSP include directive is used to include header banners and footers content.

The JSP compilation process is that, the JSP page gets compiled only if that page has changed. If the change is only in the included file, the source JSP file will not be compiled and therefore the modification will not get reflected in the browser output.



Jsp Include action
The jsp:include action element works like a function call. At runtime, the included file will be compiled & executed and the resulted output is included with the source page. When the included JSP page is called, both the request and response objects are passed as parameters.

In case we need to pass any values to the included file, then jsp:param element can be used. If the resource is static, its content is inserted into the calling JSP file, since there is no processing needed.