Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Include Directive Vs Standard Action

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Could anyone give a real life example?
 
Claudio Lande
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx, does that means in PRACTICAL terms, there is no need to bother <jsp:include> vs <@% include%> - just stick to one is enough.
 
Claudio Lande
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Hope it helps.
 
Paolo Metafune
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paolo,

For point 1, do you mean:

<jsp:include page="<%= request.getAttribute("incPage")%>" />

However, this does not compile in tomcat 5, although using EL is ok

<jsp:include page="${incPage}" />

A bit confused about when and which tag attributes support <%= %> and which requires EL syntax!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic