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

JSP: jsp:include & include diretive

 
Yanjing Liu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I am confuse about relative URL used in �jsp:include action� and �include diretive�.
Can any body explain what the meaning of the following cases?
Case 1
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�
Case 2
A.jsp says <jsp:include page=�dir/B.jsp�/> and dir/B.jsp says <jsp:include page=�C.jsp� />. In this case the relative specification �C.jsp� resolves to �dir/C.jsp�.
Case 3
A.jsp says <jsp:include page=�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�.
Case 4
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�.
Thanks in advance
Yanjing
 
Mathew Kuruvilla
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'A.jsp' is in the main directory and 'B.jsp' and 'C.jsp' are in the subdirectory dir.
Case 1
All are static inclusions, therefore the relative values are with reference to the present directory. So we have to explicitly specify the subdirectory 'dir' to signify the location of 'B.jsp' and 'C.jsp'.

Case 2
Here, all are dynamic inclusions, therefore all relative values are with reference to the directory where the jsp file is located. So to specify B.jsp from A.jsp, we give the subdirectory name. However, 'B.jsp' and 'C.jsp' are in the same directory, so the correct way to refer to 'C.jsp' for dynamic inclusion in B.jsp is to not specify the directory name 'dir'.
Case 3
Here it is a mix of case 1 and 2 above.
However, a dynamic inclusion of 'B.jsp' in 'A.jsp' shifts the relative reference to within the 'dir' subdirectory. The static inclusion of 'C.jsp' from within 'B.jsp' is then relative to the current directory, which is the 'dir' directory, and so the 'dir' directory does not have to be explicitly to resolve it correctly.
Case 4
Here again it is a mix of case 1 and 2. However, it is static inclusion in 'A.jsp' and dynamic inclusion in 'B.jsp'. So the 'dir' subdirectory has to be specified in 'A.jsp', while in 'B.jsp' it is relative to the same directory. However, this case, the static inclusion occurs first, and so the dynamic inclusion is being done from the main directory, NOT from within the 'dir' subdirectory. When a static inclusion is performed, the relative reference does not shift to the directory where the included page is located.

The underlying principle is that when we do dynamic inclusion, the relative reference shifts to where the included page is located, while for static inclusion, the relative reference does not shift, and is always with reference to the page where the static inclusion is taking place. Thus we get different resolution of web page if we do static inclusion first or dynamic inclusion first and then followed by the other type of inclusion.NOT
[ April 18, 2003: Message edited by: Mathew Kuruvilla ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic