• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between include directive &action tag

 
Priya dharshini
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

What's the difference between include directive tag & include action tag?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Priya dharshini
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried withis code. But its giving the same result.I didn't modified the source. I modified in the included file.As I request for the JSP page I got the same result for both.Please explain me.
 
Ishrayansh Nath
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ 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.

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Priya,

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
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read my last post ?
 
Priya dharshini
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. But i didn't get clearly.
 
Priya dharshini
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. But i didn't get clearly.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I'll try to be clear:

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
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the include directive with a file which is not going to change
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic