Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > jsp include

Reply
Thread Tools

jsp include

 
 
KevinRobinson
Guest
Posts: n/a
 
      04-25-2007
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


 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      04-25-2007
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

 
Reply With Quote
 
 
 
 
KevinRobinson
Guest
Posts: n/a
 
      04-25-2007
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
>



 
Reply With Quote
 
Wojtek
Guest
Posts: n/a
 
      04-25-2007
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


 
Reply With Quote
 
David P
Guest
Posts: n/a
 
      04-25-2007
test
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      04-25-2007
David P wrote:
> test


Your test failed.

Miserably.

--
Lew
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      04-26-2007
David P wrote:
Lew wrote:
>> test

>
>Your test failed.
>
>Miserably.


Note that the alt.test.* groups are wonderful for this purpose.

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

Message posted via http://www.javakb.com

 
Reply With Quote
 
KevinRobinson
Guest
Posts: n/a
 
      04-26-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Wojtek
Guest
Posts: n/a
 
      04-26-2007
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


 
Reply With Quote
 
jacma983@yahoo.fr
Guest
Posts: n/a
 
      04-28-2007
On Apr 26, 12:19 pm, "KevinRobinson" <(E-Mail Removed)>
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.




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
/* #include <someyhing.h> */ => include it or do not include it?That is the question .... Andreas Bogenberger C Programming 3 02-22-2008 10:53 AM
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM
jsp:include is not allowing me write scriptlet between <jsp:param> tags ramakrishna Java 0 05-04-2006 12:49 PM
<%JSP:include page="hello.jsp" %> Shinya Koizumi Java 3 03-12-2006 11:34 PM
jsp include and jsp param Robert Mark Bram Java 2 09-12-2005 04:25 AM



Advertisments