Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resolving a URL in include action tag?

 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
     
    Madhav Lakkapragada
    Ranch Hand
    Posts: 5040
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    knock...knock....knock...Please.
    - satya
     
    Roseanne Zhang
    Ranch Hand
    Posts: 1953
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 5040
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 5040
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    An explanation on this topic from Peter...
    enjoy!
    - madhav
     
    Anonymous
    Ranch Hand
    Posts: 18944
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 3252
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic