I understand the difference between the 2 - one like copy and paste while other is dynamically include the output of other during runtime.
But, I dont understand under what real life situation that a <%@ include %> cannot do the job and <jsp:include > must be used. Recall that the content of those included by <%@ include%> CAN be jsp construct which WILL generate dynamic content. So whether the include itself is done dynmically during runtime or page compilation should not affect the ability to achieve dynamic content.
Imagine that in your webapp you have a menu that is implemented as a JSP (say menu.jsp) that is statically imported by all other JSP. If you change the graphics/contents of menu.jsp, the pages won't reflect this change because they were not modified and still contain the template + dynamic code of old menu.jsp. In reality some containers (as Tomcat) will recognize that an included resource has changed and will regenerate the pages that include the resource, but this is not guaranteed by the spec.
SCJP 1.4, SCWCD 1.4, PMP, ITIL V3 Foundation
Joined: Jan 28, 2004
Thx, does that means in PRACTICAL terms, there is no need to bother <jsp:include> vs <@% include%> - just stick to one is enough.
Joined: Mar 24, 2005
I wouldn't put it that way... Let's say that for the exam you need to know the difference. For real life you have to know the difference too since include behaviour might change depending on the container you use. Last but not least statically including resources is more efficient but, as stated previously, does not guarantee that including pages are updated if you change included jsp...
Let's say that if you stick to a container that regenerates pages that include changed components, you are probably better off with static (directive-based) include.
Alec, in real life you can use jsp:incluse instead of include directive in these situations: 1)if you want to determine the page to include at request time because the page attribute of include action can be a request time expression. 2)if you want to pass parameters to the included page 3)if you want to include a sevlet All things that you can't do in static inclusion. A problem that you have with dynamic inclusion is that if you want to share objects with the dynamically included page you have to add these objects as attribute of the current request, while a static included page can refer to objects declared in the including page because a statically included page will be in the same tranlation unit (i mean in the same servlet) of the including page.
Tell me if everything is clear and correct for you.