The directive is used for including static content, while the action is also used for dynamic content. So the first one will include the content into the JSP only at compilation time. The second one will include the content every time you access the JSP.

The <%@include file="includeFile.jsp"%> directive acts like C "#include", pulling in the text of the included file and compiling it as if it were part of the including file. The included file can be any type (including HTML or text).

The <jsp:include page="includeFile.jsp"> tag compiles the file as a separate JSP file, and embeds a call to it in the compiled JSP.

Ishrayansh Nath
Ranch Hand

Joined: Nov 05, 2004
Posts: 45

posted Feb 22, 2006 00:09:00

0

<%@ include file="included2.jsp"%>

So the first one will include the content into the JSP only at compilation time.(Translation Phase). after you modify included2.jsp ,it won't be update(Refelect) your jsp file.

Action include <jsp:include page="included2.jsp" flush="true"/>

The second one will include the content every time you access the JSP. after you modify included2.jsp ,it will be update(Refelect) your jsp file.

About the include directive, the spec says: A JSP container can include a mechanism for being notified if an included file changes, so the container can recompile the JSP page. However, the JSP 2.0 specification does not have a way of directing the JSP container that included files have changed.

That is why the changes to your included files is reflected for both the directive and the action. It is the way your container works.

But you should not rely on this, and remember that if you really want the content to be updated at runtime, then you should use the action instead.

Priya dharshini
Ranch Hand

Joined: Aug 06, 2005
Posts: 78

posted Feb 22, 2006 00:42:00

0

I saved this file in included2.html & i saved the jsp as included2.jsp. Then i changed the html content & jsp.But i didn't modify the source jsp. While running i got the modification in both include directive & action. But in book they mentioned the modification in only in action tag part.the directive tag part not modified. I didn't get this one.

The spec says : 1. include directive should be used to include static content 2. include action should be used to include static/dynamic content.

So we expect static content NOT to be updated when using the include directive. But as you have experienced, content is actually updated, even with the include directive. Why ?

The spec also says about the include directive: A JSP container can include a mechanism for being notified if an included file changes, so the container can recompile the JSP page. However, the JSP 2.0 specification does not have a way of directing the JSP container that included files have changed.

In clear, it is up to the container to do whatever it wants. There maybe containers that will update pages using the include directive. The container you are using is acting this way. It will update the content of an included file, even when using the include directive.

BUT: The spec insists that the directive should be used for static content only, and that you should not rely on the container's behaviour.

Priya dharshini
Ranch Hand

Joined: Aug 06, 2005
Posts: 78

posted Feb 22, 2006 01:27:00

0

Then how i'll get the static behaviour while i using the directive tag in this container. Sorry really i don't know much in JSP.Please explain me.