Using Tomcat 5.5.20, I'm having no trouble with relative paths such as:

<%@ include file="../filename.inc" %>

... and we have several of them. So your original usage looks correct. I would say to be sure you didn't put the wrong index.jsp file in the main app directory.

We do not use a leading slash, since that would mean it is not a relative path. Clearly, "/../filename.jsp" is not going to work.

We do not use the ".jsp" extension for include files because pre-compiling would try to compile the include files, and Tomcat will also try to compile them if you try to access them.

Layton

Justin Jaynes wrote:
Chris,

Using "/header.jsp" which is of course an absolute path, I get virtually the 
same error.  Only /../header.jsp changes to /header.jsp  Still doesn't work.

You also suggested this: <%@ include file="<%= request.getContextPath() 
%>/header.jsp" %>
I tried it but the code inside the quotes does not get evaluated.

Justin

----- Original Message ----
From: Christopher Schultz <[EMAIL PROTECTED]>
To: Tomcat Users List <users@tomcat.apache.org>
Sent: Tuesday, November 7, 2006 6:14:58 AM
Subject: Re: Include Directive

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Justin,

The index.jsp file in the main directory contains the code <%@
include file="header.jsp" %> and it works great.

In the admin directory the index.jsp file contains this code <%@
include file="../header.jsp" %> obviously referencing to the parent
directory, where the header.jsp file sits.  I don't want to have to
copy it to the child directory and maintain two copies of it.

But when I do this, I get an error every time.  What am I doing
wrong?  You can find the error below.

It's a good idea to start your include directives with a '/', making
your paths relative to the context path (the "webapp base URI", if you
will). As you can see, Tomcat is adding a leading '/' for you, which
makes the path into nonsense:

File "/../header.jsp" not found

"/../header.jsp" would actually be located one directory above your
webapp's root directory, which is illegal.

Consider using "/header.jsp" as the include's location.

There is another thread from the last 24 hours or so with someone asking
about changing context paths. This is the best way to do this:

<%@ include file="<%= request.getContextPath() %>/header.jsp" %>

Not sure if that compiles (I haven't touched JSP in years), but it's the
general idea.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFUIbR9CaO5/Lv0PARAiNSAJ9T4mX3Vz5nMvdNN/RfyS25CmpKVQCdENMF
f09sh+IY0kXEb/MPD39Qi+Y=
=44Mk
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]







---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to