This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi Guys, I found a question from the JSP 2.0 specification: (Page I-110) if there're A.jsp, C.jsp, dir/B.jsp and dir/C.jsp: Case 1: 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. Case 2: 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.
Greately appriciate if you can tell me why case 1: is not dir/B.jsp.
Your question was: Greately appriciate if you can tell me why case 1: is not dir/B.jsp. I think the question should be why isnt it dir/C.jsp
We have A.jsp, C.jsp, dir/B.jsp and dir/C.jsp, Lets see what Case 1: does:
(i) A.jsp says <%@ include file=�dir/B.jsp�%> There is no ambiguity here - dir/B.jsp is "statically" included in A.jsp But note that this is a statical inclusion - so the dir/B.jsp code is now part of the A.jsp code. This implies that the current jsp location in not the dir folder but the same folder as A.jsp is in (ii) dir/B.jsp says <jsp:include page=�C.jsp�/>. Using the explanation in (i), in this case, the current dir of B.jsp is NOT dir, so the relative specification C.jsp resolves to C.jsp and NOT dir/C.jsp.
Here both are dynamic includes, so (i) is including dir/B.jsp into A.jsp, dynamically. When dir/B.jsp is executing, it current page folder IS dir, so it interprets the inclusion of C.jsp relative to dir => dir/C.jsp
There are 2 things to note here: 1. Both, page attribute of the include standard action & file attribute of the include directive are relative to the current jsp page. 2. There is a difference between the way a static include and dynamic include are handled, not just the time at which the include occurs (translation vs run-time) but in the "scope" of the inclusion.
BTW, you can avoid confusion by giving the relative path as "/x/y/z/myjsp.jsp". If you start with "/" then the path is interpreted from the root of your web application and not the current page, then there is no scope for ambiguity between a static vs dynamic include.
Hope this helps,
Joined: May 23, 2004
ortimus, Really greatly appreciate your elaborated explanation, it's very clear and straigtforwd, greatly appreciate your time (Even just typing those words take time, not mention to ask my questions).