This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Need help:  jsp: include relative path question! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Need help:  jsp: include relative path question! " Watch "Need help:  jsp: include relative path question! " New topic
Author

Need help: jsp: include relative path question!

Hai Lin
Ranch Hand

Joined: May 23, 2004
Posts: 79
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.

Thanks a lot!

Hai
Sumitro Palit
Ranch Hand

Joined: Dec 13, 2003
Posts: 37
Hai,

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.

Compare this with:
(i) A.jsp says <jsp:include page=�dir/B.jsp�%>
(ii)dir/B.jsp says <jsp:include page=�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,

- ortimuS
Hai Lin
Ranch Hand

Joined: May 23, 2004
Posts: 79
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).


Hai
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help: jsp: include relative path question!
 
Similar Threads
JSP: jsp:include & include diretive
Interpreting paths in jsp:include and include directive
jsp:include
current JSP page v/s current JSP file!!
include action vs. include directive