Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

jsp include

Thread view: 
KevinRobinson - 25 Apr 2007 14:14 GMT
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
Andrew Thompson - 25 Apr 2007 14:41 GMT
...
>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" %>

Signature

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

KevinRobinson - 25 Apr 2007 15:22 GMT
If I use <%@ include file="/include/amt_header.jsp" %>

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

> ..
>>So for example if my main file is in a folder "cart" and I want to access
[quoted text clipped - 9 lines]
> (from anywhere within the site).
> <%@ include file="/include/amt_header.jsp" %>
Wojtek - 25 Apr 2007 15:58 GMT
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" %>

Signature

Wojtek :-)

David P - 25 Apr 2007 18:23 GMT
test
Lew - 25 Apr 2007 23:52 GMT
> test

Your test failed.

Miserably.

Signature

Lew

Andrew Thompson - 26 Apr 2007 02:22 GMT
David P wrote:
>> test
>
>Your test failed.
>
>Miserably.

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

Signature

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

KevinRobinson - 26 Apr 2007 11:19 GMT
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

> Hi,
>
[quoted text clipped - 23 lines]
>
> Kevin
Wojtek - 26 Apr 2007 14:10 GMT
KevinRobinson wrote :
> Thanks,
>
[quoted text clipped - 19 lines]
> 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.

Signature

Wojtek :-)

jacma983@yahoo.fr - 28 Apr 2007 03:09 GMT
On Apr 26, 12:19 pm, "KevinRobinson" <k.s.robin...@btinternet.com>
wrote:
> Thanks,
>
[quoted text clipped - 19 lines]
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.