jsp include

Discussion in 'Java' started by KevinRobinson, Apr 25, 2007.

  1. Hi,

    Can anyone help me with a problem please.

    I am using the <%@ include file="/include/amt_header.jsp" %> code to include
    a header into a JSP and it works

    fine if the file which uses the include statement is in the same folder that
    contains the include folder.

    The problem is when a file wishes to use the "/include/amt_header.jsp" file
    from a different folder.

    So for example if my main file is in a folder "cart" and I want to access
    the header file contained in the folder "include" then I can't.

    I have tried the following but it won't work <%@ include
    file="../include/amt_header.jsp" %>.

    I am sure there is a siimple solution to this problem but what.

    Thanks in Anticipation.

    Kevin
     
    KevinRobinson, Apr 25, 2007
    #1
    1. Advertising

  2. KevinRobinson wrote:
    ...
    >So for example if my main file is in a folder "cart" and I want to access
    >the header file contained in the folder "include" then I can't.


    Where is 'cart'? What is the actual path from the root?

    >I have tried the following but it won't work <%@ include
    >file="../include/amt_header.jsp" %>.


    Given a leading '/' indicates 'from the root of the site',
    if that first string ever worked, then this should also work
    (from anywhere within the site).
    <%@ include file="/include/amt_header.jsp" %>

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via http://www.javakb.com
     
    Andrew Thompson, Apr 25, 2007
    #2
    1. Advertising

  3. If I use <%@ include file="/include/amt_header.jsp" %>

    File "/include/amt_header.jsp" not found.


    "Andrew Thompson" <u32984@uwe> wrote in message news:713b9b21e1d5f@uwe...
    > KevinRobinson wrote:
    > ..
    >>So for example if my main file is in a folder "cart" and I want to access
    >>the header file contained in the folder "include" then I can't.

    >
    > Where is 'cart'? What is the actual path from the root?
    >
    >>I have tried the following but it won't work <%@ include
    >>file="../include/amt_header.jsp" %>.

    >
    > Given a leading '/' indicates 'from the root of the site',
    > if that first string ever worked, then this should also work
    > (from anywhere within the site).
    > <%@ include file="/include/amt_header.jsp" %>
    >
    > --
    > Andrew Thompson
    > http://www.athompson.info/andrew/
    >
    > Message posted via http://www.javakb.com
    >
     
    KevinRobinson, Apr 25, 2007
    #3
  4. KevinRobinson

    Wojtek Guest

    KevinRobinson wrote :
    > If I use <%@ include file="/include/amt_header.jsp" %>
    >
    > File "/include/amt_header.jsp" not found.


    This is because the file include is dependant on the OS file system. So
    if you are using windows and the JSP pages are on drive X:, then the
    above statement will look for the file in X:\include.

    You must either place the fully qualified path in the include (highly
    not portable, as your development environment paths most likely do not
    match your test and production paths, or use relative paths.

    Count the directories. I have include directives which are several
    layers deep:

    <%@ include file="../../../_include/_setup.jspf" %>

    --
    Wojtek :)
     
    Wojtek, Apr 25, 2007
    #4
  5. KevinRobinson

    David P Guest

    Subject

    test
     
    David P, Apr 25, 2007
    #5
  6. KevinRobinson

    Lew Guest

    Re: Subject

    David P wrote:
    > test


    Your test failed.

    Miserably.

    --
    Lew
     
    Lew, Apr 25, 2007
    #6
  7. Andrew Thompson, Apr 26, 2007
    #7
  8. Thanks,

    the ../ worked eventually.

    Just one other related question.

    If the header.jsp (in the include folder) contains for example <a
    href="/email/join_email_list.jsp"> and if
    the jsp that I want to use the header in is in the same directory as the
    include folder
    then I use <%@ include file="/include/amt_header.jsp" %>.

    If the jsp that I want to use the header in is in one folder down then I
    use:-
    <%@ include file="../include/amt_header.jsp" %>.

    If I use a jsp with the header in a different folder say 'cart' and I use
    <%@ include file="../include/amt_header.jsp" %> then it works with
    hrefs pointing to the root but the <a href="/email/join_email_list.jsp"> no
    longer works.

    Is there a way round this without having to have 2 header files the second
    containing <a href="../email/join_email_list.jsp">

    Thanks




    "KevinRobinson" <> wrote in message
    news:...
    > Hi,
    >
    > Can anyone help me with a problem please.
    >
    > I am using the <%@ include file="/include/amt_header.jsp" %> code to
    > include
    > a header into a JSP and it works
    >
    > fine if the file which uses the include statement is in the same folder
    > that
    > contains the include folder.
    >
    > The problem is when a file wishes to use the "/include/amt_header.jsp"
    > file
    > from a different folder.
    >
    > So for example if my main file is in a folder "cart" and I want to access
    > the header file contained in the folder "include" then I can't.
    >
    > I have tried the following but it won't work <%@ include
    > file="../include/amt_header.jsp" %>.
    >
    > I am sure there is a siimple solution to this problem but what.
    >
    > Thanks in Anticipation.
    >
    > Kevin
    >
    >
     
    KevinRobinson, Apr 26, 2007
    #8
  9. KevinRobinson

    Wojtek Guest

    KevinRobinson wrote :
    > Thanks,
    >
    > the ../ worked eventually.
    >
    > Just one other related question.
    >
    > If the header.jsp (in the include folder) contains for example <a
    > href="/email/join_email_list.jsp"> and if
    > the jsp that I want to use the header in is in the same directory as the
    > include folder
    > then I use <%@ include file="/include/amt_header.jsp" %>.
    >
    > If the jsp that I want to use the header in is in one folder down then I
    > use:-
    > <%@ include file="../include/amt_header.jsp" %>.
    >
    > If I use a jsp with the header in a different folder say 'cart' and I use <%@
    > include file="../include/amt_header.jsp" %> then it works with
    > hrefs pointing to the root but the <a href="/email/join_email_list.jsp"> no
    > longer works.
    >
    > Is there a way round this without having to have 2 header files the second
    > containing <a href="../email/join_email_list.jsp">


    You are mixing up URL paths with OS paths.

    In a URL the / means start from the web server root.

    In an OS path the / (or \) means start from the drive root.

    So your includes would take into consideration where they are in your
    path structure, whereas your URLs always use the same text.

    The URL <a href="/email/join_email_list.jsp"> will always be the same
    regardless of which page it is in.

    --
    Wojtek :)
     
    Wojtek, Apr 26, 2007
    #9
  10. KevinRobinson

    Guest

    On Apr 26, 12:19 pm, "KevinRobinson" <>
    wrote:
    > Thanks,
    >
    > the ../ worked eventually.
    >
    > Just one other related question.
    >
    > If the header.jsp (in the include folder) contains for example <a
    > href="/email/join_email_list.jsp"> and if
    > the jsp that I want to use the header in is in the same directory as the
    > include folder
    > then I use <%@ include file="/include/amt_header.jsp" %>.
    >
    > If the jsp that I want to use the header in is in one folder down then I
    > use:-
    > <%@ include file="../include/amt_header.jsp" %>.
    >
    > If I use a jsp with the header in a different folder say 'cart' and I use
    > <%@ include file="../include/amt_header.jsp" %> then it works with
    > hrefs pointing to the root but the <a href="/email/join_email_list.jsp"> no
    > longer works.
    >
    > Is there a way round this without having to have 2 header files the second
    > containing <a href="../email/join_email_list.jsp">


    As wotjek told you, you are confusing two unrelated things:

    - the <a href="../..."> shall be resolved by the Web browser of the
    user visiting the site if/when it clicks on the link.

    - the 'include' is resolved by your servlet container (e.g. Tomcat)
    when it will process your .jsp file

    Relatives "includes" (i.e. those not starting with a '/') are always
    relative to the directory of the .jsp file they appear in.
     
    , Apr 28, 2007
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Mark Bram

    jsp include and jsp param

    Robert Mark Bram, Sep 8, 2005, in forum: Java
    Replies:
    2
    Views:
    5,979
    Robert Mark Bram
    Sep 12, 2005
  2. Shinya Koizumi

    <%JSP:include page="hello.jsp" %>

    Shinya Koizumi, Mar 9, 2006, in forum: Java
    Replies:
    3
    Views:
    9,741
    Raymond DeCampo
    Mar 12, 2006
  3. ramakrishna
    Replies:
    0
    Views:
    1,266
    ramakrishna
    May 4, 2006
  4. Replies:
    0
    Views:
    4,438
  5. Andreas Bogenberger
    Replies:
    3
    Views:
    958
    Andreas Bogenberger
    Feb 22, 2008
Loading...

Share This Page