• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:include and %@include

 
Aniket Patil
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The spec mentions
The page attribute of both the jsp:include and the jsp:forward actions are interpreted relative to the current JSP page, while the file attribute in an include directive is interpreted relative to the current JSP file.


It further gives an example:

consider the following four situations built using four JSP files: A.jsp, C.jsp, dir/B.jsp and dir/C.jsp:
� A.jsp says <%@ include file=�dir/B.jsp�%> and dir/B.jsp says <%@ include
file=�C.jsp�%>. In this case the relative specification �C.jsp� resolves to �dir/C.jsp�

� A.jsp says <%@ include file=�dir/B.jsp�%> and dir/B.jsp says <jsp:include
page=�C.jsp�/>. In this case the relative specification �C.jsp� resolves to
�C.jsp�.

How does the above work out and what does the statement mean?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A.jsp
dir/B.jsp
dir/C.jsp <-- relative to the current JSP file (B.jsp)

A.jsp
dir/B.jsp
C.jsp <-- relative to the current JSP page (A.jsp)
 
Aniket Patil
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satou,

I still can't understand why C.jsp is picked in one case and dir/C.jsp in the other. Can you explain?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In both examples, the current file is B and the current page is A. If you include C in B, using "include file" will then be relative to B, and "include page" relative to A.
 
Aniket Patil
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For more information, refer http://faq.javaranch.com/view?ScwcdHints
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic