Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp:include action vs @ include directive  RSS feed

 
Ek Chotechawanwong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,
I am very curious about how the JSP container would compute the URL specified by <jsp:include page=...> and <%@include file=...>.
JSP 1.2 and 2.0 spec I just read just increase my curiosity.
Quoting an example from article JSP.5.4 of Sun's jsp-2_0_fr-spec,

For an example of a more complex set of inclusions, 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 <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.
- 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.
- 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.

Could you please explain the reason why we get these result ... case by case?
Ek
 
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@include file=...> inserts that file into the file with the command before the file is converted to java. The included file becomes part of the including file. This is done during the translation phase (when the jsp is turned into java) so it will be done when it is encountered in the jsp.
<jsp:include page=...> incorporates the response from the included jsp's java by executing it. The included file's response is displayed along with the response from the including file. This is done during the request processing phase, so it will be done when it is encountered in the java.
Given the above,
Example 1: A.jsp says to incorporate file dir/B.jsp which says to incorporate file C.jsp, dir/B.jsp is being translated from dir, so dir/C.jsp is relative to dir/B.jsp.
Example 2: A.jsp says to incorporate the response of dir/B.jsp, which says to incorporate the response of C.jsp. dir/B.jsp is being called in place (dir), so dir/C.jsp is relative.
Example 3: A.jsp says to incorporate the response of dir/B.jsp, which says to incorporate file C.jsp. dir/B.jsp is again being invoked in place, so dir/C.jsp is relative.
Example 4: A.jsp says to incorporate the file dir/B.jsp, which will be done before dir/B.jsp <jsp:includes C.jsp, essentially making a larger A.jsp, when the <jsp:includes line is executed, C.jsp is relative, as that line is now in the larger A.jsp
hth
 
Ek Chotechawanwong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ray,
This makes sense.
Thank so much.
Ek
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!