Bug 39817

Summary: Include File Failure for Parent|Top Relative References
Product: Tomcat 5 Reporter: James B. Crocker <james.crocker>
Component: Servlet & JSP APIAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED INVALID    
Severity: normal CC: esandusky
Priority: P2    
Version: 5.0.17   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Bug Depends on:    
Bug Blocks: 41261    
Attachments: A minimal test war to demonstrate the issue

Description James B. Crocker 2006-06-15 18:45:10 UTC
While using the <%@ include file="" %> a Jasper exception for file not found is
generated when the target file is in a parent|top location. (Current and
subordinate directory file references are successfull.)

jdk 1.5.0_07
tomcat 5.5.17

server.xml appBase="/topdir/webapp" docBase="" path=""

topdir -
   webapp -
      parenttarget.jsp
      dir1 -
         inc.jsp
         peertarget.jsp
         subdir -
            subtarget.jsp

      
inc.jsp eg.
<%@ include file="../parnenttarget.jsp" %> FAILS file not found for
"/../parenttarget.sjp"
<%@ include file="/parenttarget.jsp" %> FAILS file not found for "/parenttarget.sjp"
<%@ include file="peertarget.jsp" %> OK
<%@ include file="subdir/subtarget.jsp" %> OK
Comment 1 Mark Thomas 2006-06-18 23:27:28 UTC
I have just tested this with the latest 5.5.x source and everything works as
expected.

I assumed the parenttarget.sjp was a typo in the bug report but could it be a
typo in your test case as well?
Comment 2 Michael Johnston 2006-07-21 17:56:40 UTC
I have just upgraded from 5.5.7 to 5.5.17 and I immediately found a problem
similar to the one described above.

Those web applications which have include statements similar to

<%@ include file="/_jspf/global.jspf" %>

in files contained within a sub directory of the appBase throw the following
error when the page is accessed:

org.apache.jasper.JasperException: /index.jsp(2,0) File "/_jspf/global.jspf" not
found

The same line works perfectly in files contained within the appBase itself.

This has happened across the board with every one of my web applications, none
of which displayed a problem 5 minutes before, when running within Tomcat 5.5.7.

I have tried substituting the include line for the following:

<%@ include file="../_jspf/global.jspf" %>

which merely changes the error description string to the following:

org.apache.jasper.JasperException: /index.jsp(2,0) File "/../_jspf/global.jspf"
not found

I am convinced this problem in not related to a typo or other such developer
mistake due to the blanket effect on all my applications and the abscenece of
any problem during build in Netbeans IDE 5.0 which helpfully checks all include
file references on compile.

Tomcat is running as a service on my Windows XP machine, is using jre1.5.0_07,
and is connected to Apache HTTP Server 2.0.58 using the appropriate build of 
mod_jk.
Comment 3 Mark Thomas 2006-07-21 22:38:26 UTC
Given I cannot re-reproduce this, please attach a minimal test war that
demonstrates this issue.
Comment 4 Michael Johnston 2006-07-22 09:34:52 UTC
Created attachment 18625 [details]
A minimal test war to demonstrate the issue

When accessing /index.jsp the HTML contained within /_jspf/global.jspf is
displayed without error. When accessing /subdir/index.jsp, which is idential to
/index.jsp, the following error is thrown:

org.apache.jasper.JasperException: /index.jsp(1,1) File "/_jspf/global.jspf"
not found

The web application "test" is running on a Virtual Host www.test.com on
localhost with the following mod_jk lines in httpd.conf

JkAutoAlias "<insertpathhere>/test"
JkMount /*.jsp ajp13w
JkMount /subdir/* ajp13w

and the following Host tag in server.xml

<Host name="test.com" appBase="<insertpathhere>/test" >
  <Alias>www.test.com</Alias>
  <Context path="" docBase="" debug="1"/>
</Host>
Comment 5 Mark Thomas 2006-07-22 18:16:45 UTC
I can now reproduce this. Note that httpd and JK are not part of this, I
reproduced it on Tomcat standalone.

This report is invalid as it is caused by a configuration error. That it worked
in earlier versions was luck and due to how Tomcat handled dirs in the appbase.

The current behaviour is:
Any directory in an appbase gets deployed as a webapp. Therefore _jspf and
subdir get deployed as webapps (as well as the appbase itself due tot he context
with docBase=""). The relative paths don't work across contexts, hence the failure.

A possible untested workaround is to turn off autodeployment for the appbase.

The correct approach is to:
- remove the context declaration with docBase="" from server.xml
- place the root context for the host in a directory called ROOT

Further assistance on configuration is available from the online docs and the
users mailing list.
Comment 6 Michael Johnston 2006-07-22 19:26:17 UTC
The above approach, together with ammending the include line in
ROOT/subdir/index.jsp to

<%@ include file="../_jspf/global.jspf" %>

does indeed solve the problem.

Many thanks and apologies for the misconfiguration on my part.
Comment 7 Mark Thomas 2006-07-27 21:07:26 UTC
*** Bug 40130 has been marked as a duplicate of this bug. ***
Comment 8 Eric Sandusky 2006-07-28 15:47:23 UTC
(In reply to comment #7)
> *** Bug 40130 has been marked as a duplicate of this bug. ***

Can you please expand on how to alter the Tomcat configuration, as the online 
docs do not explain this?  Changing all of my "include file=" is not an 
option.  I find it strange how a sub-release of Tomcat (5.5.12 to 5.5.17) 
requires not only changes to Tomcat setup, but also changes to my code.

My setup is as follows:

server.xml
<host name="concept" appBase="D:\webapps\Concept"/>

ROOT.xml (under Catalina/concept folder)
<context path="" docBase=""/>

Code structure

d:\webapps\Concept\catalog (contains jsps)
d:\webapps\Concept\core (contains jsps)
d:\webapps\Concept\WEB-INF (contains compiled classes/libs)

/core/*.jsp are included properly
/catalog/*.jsp are NOT included properly

What is the difference between those 2 folders?

Tomcat Manager shows a "context" for each JSP folder (catalog, core, etc).  
Why is this changed from previous versions?

Comment 9 william.barker 2006-08-01 19:27:15 UTC
*** Bug 40155 has been marked as a duplicate of this bug. ***