• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

include doesn't recognize relative path from sub folder

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tomcat 5.5.25

I have an /includes folder on document root level. All JSPs have
this include <%@ include file="/includes/header.jsp" %>

It works fine for jsps on the top level, like /index.jsp but it doesn't work for any jsps that are in sub folders, like /article/index.jsp

I get file not found error
org.apache.jasper.JasperException: /article/index.jsp(8,0) File "/includes/header.jsp" not found

Btw, if I do<%@ include file="../includes/header.jsp" %> I get
File "/../includes/header.jsp" not found

Any idea why?

Thanks!

My configs can be found here:
https://coderanch.com/forums/f-56/Tomcat

[ February 14, 2008: Message edited by: Axel Brown ]

[ February 15, 2008: Message edited by: Axel Brown ]

[ February 17, 2008: Message edited by: Bear Bibeault ]
[ February 17, 2008: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have an /includes folder on document root level.



What, exactly, do you mean when you say "document root level"?
Where is this directory?
 
Axel Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, by that I mean appBase path. Includes don't work from folders for either my domain or sub domains or addon domains...

In case of main domain: my "root" is /home/myuser/public_html
In case of addon or subdomain: /home/myuser/public_html/myaddondomain

Even if I include full path inside include, either

or

I get File not found error with "/" in front!

File "/http://www.outervision.com/includes/header.jsp" not found or
File "/home/outerv2/public_html/includes/header.jsp" not found

server.xml part:


[ February 15, 2008: Message edited by: Axel Brown ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "/" in the include path means the root of this web application (context).
Each <Context .../> entry in your server.xml file is a separate web application.

Are you trying to include files across contexts?
If so, why?

If the applications are identical, why not just use host aliases to point all requests to the same application?
If they are different, I would avoid trying to share resources between them.
Tools like Ant make it very easy to replicate files at build time so each of your applications can complete and self contained.
[ February 16, 2008: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way:
You don't need to bribe people here.
Well formed questions tend to get plenty of attention and yours seems fine.
 
Axel Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was desperate... Still, problem not resolved and I moved to old server

No, I'm not trying to include files across contexts.
Applications are different but use the same DB.

Very strange problem. Tomcat treats every sub-folder as it has its own context path or something... As soon as I copy includes folder inside sub-folder, it works.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Axel Brown:

No, I'm not trying to include files across contexts.
Applications are different but use the same DB.



Context and application are synonymous.
As far as includes are concerned, it doesn't matter that they're using the same database.

If you're trying to include a file from a different application you're going to run into trouble.

When you said you moved it to the old server, does that mean that this is working in a different container?
[ February 17, 2008: Message edited by: Ben Souther ]
 
Axel Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:


Context and application are synonymous.
As far as includes are concerned, it doesn't matter that they're using the same database.

If you're trying to include a file from a different application you're going to run into trouble.

When you said you moved it to the old server, does that mean that this is working in a different container?

[ February 17, 2008: Message edited by: Ben Souther ]



Includes fail within the same application when called from sub-folders.
Old server (shared hosting) has similar configuration except Tomcat is I believe 5.5.12 (or 19).
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It really sounds to me that you're trying to include files from other web applications (contexts) which doesn't work.

I think your best bet is to look at the two options mentioned earlier.
1.) Have only one application with aliases to handle addition domains.
2.) Duplicate the files at build time with a tool such as Ant instead of trying to share them.
 
Axel Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
It really sounds to me that you're trying to include files from other web applications (contexts) which doesn't work.

I think your best bet is to look at the two options mentioned earlier.
1.) Have only one application with aliases to handle addition domains.
2.) Duplicate the files at build time with a tool such as Ant instead of trying to share them.


No sharing, no other applications. Let's forget about multiple contexts for a minute.
I can remove all of them and leave only main domain in server.xml - and still, includes from sub-folders fail.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And the sub folders are inside your web app?

The root of a web app is the directory that holds the WEB-INF directory.
Where are your include files in relation to that?
 
Axel Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
And the sub folders are inside your web app?

The root of a web app is the directory that holds the WEB-INF directory.
Where are your include files in relation to that?



Yes, they are inside. Rigt, WEB-INF is in root.
The structure of root (public_html) like this:

articles
includes
WEB-INF
index.jsp

articles folder contains its own jsps.
includes folder contains header.jsp (our shared include between all jsps)

index.jsp from root uses /includes/header.jsp and other jsps from articles/ suppose to use the same /includes/header.jsp - but it fails for them (not found), while works for index.jsp from root.
[ February 17, 2008: Message edited by: Axel Brown ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
3 Ideas:

1.) Have you checked your log files for JSP compilation errors?

2.) Can you reproduce this in a small webapp? If so, war it up and
email it to me. I'll try it in another machine.

3.) I just created a small (working) example.
If you like, you can grab the war file here.
Try downloading and running that to see if it works.
 
Axel Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
3 Ideas:

1.) Have you checked your log files for JSP compilation errors?

2.) Can you reproduce this in a small webapp? If so, war it up and
email it to me. I'll try it in another machine.

3.) I just created a small (working) example.
If you like, you can grab the war file here.
Try downloading and running that to see if it works.



Yeah, I can reproduce it with small webapp. I just deployed your war (thanks btw), which works fine on the root level with index.jsp

As soon as I created folder /articles and copied your index.jsp to it and tried to access like this: www.example.com/articles/index.jsp - include doesn't work.

This is what I get in browser:



and this is from Tomcat's log:
 
Axel Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, I see this in tomcat's log after its restart:

 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That looks as if the manager and admin applications were removed from the hard drive but not from the config. Why would you have removed these apps? They're really useful. Especially the manager app which could be used in this case to see what contexts are deployed. For example, do you accidentally have an includes context deployed?
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. I removed the "reward" offer. That's rather inappropriate and I don't want any precedents set.
 
Axel Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
That looks as if the manager and admin applications were removed from the hard drive but not from the config. Why would you have removed these apps? They're really useful. Especially the manager app which could be used in this case to see what contexts are deployed. For example, do you accidentally have an includes context deployed?



I have no idea why an how they were removed... As long as they are not the cause of my issue.

So what about my previous post?

"Yeah, I can reproduce it with small webapp. I just deployed your war (thanks btw), which works fine on the root level with index.jsp

As soon as I created folder /articles and copied your index.jsp to it and tried to access like this: www.example.com/articles/index.jsp - include doesn't work."
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just added an 'articles' directory to the example app that I sent to you and it worked.

Can you email the small app to me?
[email protected]

Also, create a small JSP with this in it:
<%=application.getRealPath("/")%>

And see what that prints.
Put in the root directory and in the articles directory.
See if they both print the same thing.
[ February 17, 2008: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm wondering if nesting one host inside another's directory structure like this is causing your problem.

To simplify things, try running with just one host until you get things working.


 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the same exact problem too. What is the solution? I have found that it is not due to the catalina.policy and web.xml settings.
Older versions of tomcat works, but 5.5.26 says that the file isn't found. It doesn't like any includes that gives relative path like "../test.jsp".
I am having this problem of FreeBSD 6.3.

Thanks
 
A Aflatooni
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just another note:
I managed to duplicate this under windows as well.
It doesn't occur if your host and context are under webapps, but if it is pointing to a directory outside of Tomcat then you can include files from the same directory or sub-directories. But you will get an error is you want to include a file from a higher directory "../xxx".

Previous versions didn't have this problem.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A Aflatooni,
Please ask you question in a separate thread.
If you think your issue is related to this one, feel free to link to it from yours. Adding your issue to the end of this one (even if similar) is called thread hi-jacking and is very frustrating to both the original poster and the people trying to help with the original question.
 
Axel Brown
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The solution, which kind of goes against what worked in older versions of Tomcat (I believe 5.5.12), doesn't work for 5.5.25 and 5.5.26 anymore. At least in my case.

So, Context path="" or Context path="/" is no go. I figured a way to make it work by creating a folder ROOT in main domain and each sub-domains and updating Context path as in example below.

So, the folder structure will be like this:

public_html/ROOT
public_html/ROOT/sub-dom1/ROOT
public_html/ROOT/sub-dom2/ROOT
public_html/ROOT/addondomain1/ROOT
...

And all your content should be placed in ROOT of each domain, addon doamin or sub-domain respectively.

Your Host/Context will have to be updated to (note that appBase and docBase stay the same as before):



Also, in Apache's httpd.conf you have to update DocumentRoot to if you want PHP to be working. But this is only if you used JkMount /*
DocumentRoot /home/myuser/public_html/myaddondomain/ROOT

So, it works fine now. Any comments on possible security issues with this structure?
[ February 27, 2008: Message edited by: Axel Brown ]
 
Looky! I'm being abducted by space aliens! Me and this tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic