Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-18-2004, 12:04 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
jsp include

the path from where i begin for my jsp includes is inconsistant and makes no sense.

here is my file/directory structure:
index.jsp
inc/head.jsp
inc/navigation.jsp
dir2/index.jsp
dir2/inc/navigation.jsp

from index.jsp, i include "inc/head.jsp" which includes inc/navigation.jsp like this:
head.jsp
Code:
<jsp:include page="./inc/navigation.jsp" />
from dir2/index.jsp i include the same head.jsp in the lower include directory. i want to include the dir2/inc/navigation.jsp though
head.jsp included from dir2/index.jsp
Code:
<jsp:include page="../dir2/inc/navigation.jsp" />
in the first example, my include starts from the root directory of this web app './'

in the second example, my include starts from the same directory as the head.jsp './inc/'

is this normal? i've spent the last hour making sure i wasn't going crazy, but the second example is definately making me start the path from the first ./inc directory.
__________________
Mike

Last edited by sde; 08-18-2004 at 12:28 PM.
sde is offline   Reply With Quote
Old 08-18-2004, 01:11 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
I'm not sure I follow, your description of the problem was a bit convoluted. If you could explain it again, I could probably help you. In the mean time, here's what I know on the subject.

A jsp:include is processed, then the results returned to the calling jsp. This, as far as I understand, happens fairly atomically, as only the results, instead of the code, is returned to the calling jsp.

What I do is include from the root, not relative to the jsp. I find I can largely avoid these sort of problems. Plus I can then move around the jsp and not worry about links breaking (at least from within the moved jsp).
__________________
GitS
Belisarius is offline   Reply With Quote
Old 08-18-2004, 01:48 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
this might get too wordy..

this project has a LOT to it, so i want to develop it in modules. each module is a sub-directory of the web app root.

the head and foot of the web app in its entirety will be the same, so i want to use the same files for that.

the navigation which resides in the head is going to change based on what module (sub directory) you are currently working in.


example:
webroot/index.jsp
webroot/inc/head.jsp
webroot/inc/foot.jsp
webroot/module1/index.jsp
webroot/module1/inc/navigation.jsp

below is an example of my: webroot/module1/index.jsp
PHP Code:
<jsp:include page="../inc/head.jsp">
  <
jsp:param name="title" value="Customer Management" />
  <
jsp:param name="pathtoroot" value="../" />
  <
jsp:param name="navfile" value="module1/inc/navigation.jsp" />
</
jsp:include>

<
jsp:include page="../inc/foot.jsp" /> 
Here is how i use those in /webroot/inc/head.jsp
PHP Code:
<%@page contentType="text/html" pageEncoding="UTF-8">
<%
// set root http path for image and misc links to work
String pathtoroot "./";
if( 
request.getParameter("pathtoroot") != null ){
  
pathtoroot request.getParameter("pathtoroot");
}

// set navigation file
String navfile pathtoroot+"./inc/navigation.jsp";
if( 
request.getParameter("navfile") != null ){
  
navfile "../"+request.getParameter("navfile");
}
%>

<!-- 
some html here -->

<
jsp:include page="<%=navfile%>">

<!-- 
more html here --> 
you can see that if the navfile is null, it just uses the path relative to the web root, .. however, when i'm accessing it from a lower directory, i send in the navfile variable, and have to back down out of the /webroot/inc/ directory (../) then add the path from the webroot to my module1/inc/navigation.jsp

summarized: it makes sense to me that my include path to module1/inc/navigation.jsp from module1/index.jsp should be relative to module1/index.jsp. instead, it is relative to my header include which is '/webroot/inc/head.jsp'

if that is how it works, then that is fine and dandy, i can accept that. what baffles me is that why when i call '/webroot/index.jsp' is the path relative to '/webroot/index.jsp' and not '/webroot/inc/head.jsp' ???

sorry for the lengthy reply, .. i figured out how to do it, .. i just don't know why it works that way. this makes me love php more and more.
__________________
Mike
sde is offline   Reply With Quote
Old 08-18-2004, 03:35 PM   #4 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
I'm still digesting this, but I just wanted to mention that it took me forever to figure out why your jsp parameters were so messed up. Smilies have thwarted us once again!
__________________
GitS
Belisarius is offline   Reply With Quote
Old 08-18-2004, 03:49 PM   #5 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
Just to get this out of the way, these are all in the same webapp, right? I'm not sure how websphere does this, but with Tomcat, you declare a seperate context for each webapp, and if you reference between them things break.

That being said, I think I understand what's going on. Let me know if I'm wrong.

First off, remember I said the included JSP is processed first, and the resulting output returned to the calling JSP, and this happens pretty much atomically. Here's the order in which you coded things:

/webroot/module1/index.jsp -> /webroot/inc/head.jsp -> /webroot/inc/navigation.jsp

The JSP index.jsp sees an include for head.jsp, and will open the JSP file, accordingly relative to the location of index.jsp.

Now head.jsp is processed. This is largely independant of index.jsp. It sees an include for navigation.jsp. It loads and parses the JSP relative to *itself*, just as index.jsp did.

I haven't actually run tests on this, but it's what I think is going on.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 08-19-2004, 06:02 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
ok, i need to correct one thing. your path for module 1 navigation is:

/webroot/module1/index.jsp -> /webroot/inc/head.jsp -> /webroot/inc/module1/inc/navigation.jsp

i understand that since that nav is being included in head.jsp, it is relative to /webroot/inc/

re:

/webroot/index.jsp -> /webroot/inc/head.jsp -> /webroot/inc/navigation.jsp

in this set of includes, why is navigation relative to /webroot/ and not /webroot/inc/ like the module1 example.

i'm just trying to communicate exactly the inconsistancies i'm seeing. i can see how it's working, i just don't know why. i don't need to know that bad.
__________________
Mike
sde is offline   Reply With Quote
Old 08-19-2004, 06:47 AM   #7 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
I don't mind solving mysteries. Keep the info coming as this seems to be a bit hard to describe.

Honestly, I wasn't able to recreate the problem. I think it has to do with the way you setup paths via navfile and pathroot. I setup the following files:

dir2/index.jsp
dir2/inc/head.jsp
dir2/inc/navigation.jsp

All they did was print out their name, and include using relative paths, going from index.jsp -> head.jsp -> navigation.jsp, always starting with a "./". Everything ran, I didn't have a problem.
__________________
GitS
Belisarius is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On


Similar Threads
Thread Thread Starter Forum Replies Last Post
jsp: display class? sde Java 1 10-19-2004 01:02 PM
jsp page triggering twice sde Java 1 09-01-2004 08:32 AM
JSP Redirect to a relative path sde Java 1 07-06-2004 01:42 PM
viewing exception of a class from jsp sde Java 9 04-28-2004 12:58 PM
JSP on Redhat 9 sde Java 3 03-17-2004 07:03 PM


All times are GMT -8. The time now is 02:39 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting