aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Resolving a URL in include action tag? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Resolving a URL in include action tag?" Watch "Resolving a URL in include action tag?" New topic
Author

Resolving a URL in include action tag?

Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Can someone explain a little more elaborately why these examples are valid?
Thanks.
- satya

Section JSP.4.4 < jsp:include>

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. See below for some
examples of combinations of this.
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”.

    [ January 10, 2002: Message edited by: Madhav Lakkapragada ]

    Take a Minute, Donate an Hour, Change a Life
    http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
    Madhav Lakkapragada
    Ranch Hand

    Joined: Jun 03, 2000
    Posts: 5040
    knock...knock....knock...Please.
    - satya
    Roseanne Zhang
    Ranch Hand

    Joined: Nov 14, 2000
    Posts: 1953
    Write 4 files as indicated, put some simple code like <h1>c.jsp</h1> in the page, then test it out!
    The same way as you do the SCJP.
    [ January 12, 2002: Message edited by: Roseanne Zhang ]
    Madhav Lakkapragada
    Ranch Hand

    Joined: Jun 03, 2000
    Posts: 5040
    Roseanne:
    psstt!
    You see these stmts are from the JSP Spec.
    So I trust them. They will definetly work.
    My problem is with the explanation. Not what the result will be.
    Okay, maybe I should read them for the fifth time....
    Anyways will give it a shot, Thanks.
    - satya
    Madhav Lakkapragada
    Ranch Hand

    Joined: Jun 03, 2000
    Posts: 5040
    An explanation on this topic from Peter...
    enjoy!
    - madhav
    Anonymous
    Ranch Hand

    Joined: Nov 22, 2008
    Posts: 18944
    So What I understood is
    using include directive I cant include servlets but only jsp files or html files. but using jsp action I can include servlet/jsp/html
    Is this correct understanding???
    Peter den Haan
    author
    Ranch Hand

    Joined: Apr 20, 2000
    Posts: 3252
    Yes, that's more or less it. Remember, the <%@include %> directive is much like the C/C++ #include. The file is read and inserted in the JSP source before compilation. The file has to be valid chunk of JSP code.
    On the other hand, the <jsp:include > action translates into a run-time call to RequestDispatcher.include(). The indicated JSP, servlet or whatever is invoked and the HTML output incorporated in the response. It doesn't matter whether the included resource is JSP or not, as long as it generates HTML.
    So you see they work on completely different levels. In general, directives do their job at compile time while actions do their job at run time.
    - Peter
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Resolving a URL in include action tag?