This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JSP and the fly likes diff between include action and include directive Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "diff between include action and include directive" Watch "diff between include action and include directive" New topic
Author

diff between include action and include directive

sumeet29
Greenhorn

Joined: Dec 20, 2001
Posts: 1
Can anybody tell me diff. between include action and include directive ie.
<%@ include file="" %> -------------directive
<jsp:include page="filename" /> -------action
please tell me in details with example
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
They are very different in principle but accomplish similar functions in practice.
The directive just includes the TEXT of the included file in the main file AND THEN compiles the resulting page as ONE page therefore creating ONE corresponding servlet.
With the action, the included file is a SEPARATE servlet which is executed at request time and its output "chained" to the including servlet.


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

Here's a link you might want to visit:
http://java.sun.com/j2ee/blueprints/web_tier/qanda/index.html#directive
This section of Sun's J2EE Blueprints answers common questions related to J2EE applications' Web tiers. This section also discusses the differences between the two JSP include mechanisms and offers suggestions for deciding which mechanism to use for a given situation.
taken from this JavaWorld article on JSP Best Practices: http://www.javaworld.com/javaworld/jw-11-2001/jw-1130-jsp.html?
Junilu


Junilu - [How to Ask Questions] [How to Answer Questions]
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

Originally posted by Tony Alicea:
They are very different in principle but accomplish similar functions in practice.
The directive just includes the TEXT of the included file in the main file AND THEN compiles the resulting page as ONE page therefore creating ONE corresponding servlet.
With the action, the included file is a SEPARATE servlet which is executed at request time and its output "chained" to the including servlet.

Right... another way to think of it is the directive version is a static include -- it is a partial JSP page that normally is not run on its own (maybe a header or footer that you use on all your pages.
The action version is a dynamic include it is a full JSP that is executed, and its output is included in the parent JSP.
------------------
- Jessica Bradley
HP Bluestone
[This message has been edited by Jessica Bradley (edited December 20, 2001).]


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

Note too that the action version (<jsp:include> ) can include a static resource. I'm not quite clear on how the server determines whether a resource is static and dynamic though. Files that have the JSP extensions are dynamic and other extensions such as HTML, JS, TXT will normally be static. But you can have index.html mapped to a dynamic resource as well.
Jessica or Tony, would either one of you care to explain this further?
Thanks,
Junilu
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
Sumeet29:
Welcome to JavaRanch!
I would like to direct you to our username policy at:
http://www.javaranch.com/ubb/Forum10/HTML/000180.html
Please re register and come back! Thank,
---
Sheriff Tony
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: diff between include action and include directive
 
Similar Threads
Difference between Include Directive and Include Action
exact difference between include action and include directive
reg. sendRedirect
Differences
including content in jsp from action class ?