File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes difference between include directive &action tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "difference between include directive &action tag" Watch "difference between include directive &action tag" New topic
Author

difference between include directive &action tag

Priya dharshini
Ranch Hand

Joined: Aug 06, 2005
Posts: 78
Hi all,

What's the difference between include directive tag & include action tag?


Thanks & Regards,
Priyadharshini . T
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Priya dharshini
Ranch Hand

Joined: Aug 06, 2005
Posts: 78
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

Joined: Nov 05, 2004
Posts: 45
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
<%@ 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

Joined: Nov 24, 2005
Posts: 14688
    
  16

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

Joined: Aug 06, 2005
Posts: 78
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

Did you read my last post ?
Priya dharshini
Ranch Hand

Joined: Aug 06, 2005
Posts: 78
Yes. But i didn't get clearly.
Priya dharshini
Ranch Hand

Joined: Aug 06, 2005
Posts: 78
Yes. But i didn't get clearly.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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

Joined: Aug 06, 2005
Posts: 78
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

Use the include directive with a file which is not going to change
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between include directive &action tag