aspose file tools*
The moose likes Tomcat and the fly likes Can't inlculde files from a parent directory in new tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Can Watch "Can New topic
Author

Can't inlculde files from a parent directory in new tomcat

A Aflatooni
Greenhorn

Joined: May 03, 2006
Posts: 8
There is a problem with including files from a parent directory in tomcat 5.5.26. I have tried this on windows and freebsd with the same effect.
The catch is that if the appdocs in the host container is something other than webapps and defined as an absolute path you will get a "file not found error". I.e you will not be able to include file="../test.jsp" but files from sub directories work. Please note that file="../test.jsp" would still be in the context path.

This was discussed in the thread:

http://www.coderanch.com/t/87476/Tomcat/include-doesn-recognize-relative-path

Has anyone found what the problem is? and is there a solution? I have checked the catalina.policy and everything is ok and I also found that tomcat 5.5.12 doesn't have this problem.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

The solution is to avoid page-relative addressing and to use context-relative addressing.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
A Aflatooni
Greenhorn

Joined: May 03, 2006
Posts: 8
This is context-relative includes that I get an error on.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

Please include your web app structure and the paths that you are using.
A Aflatooni
Greenhorn

Joined: May 03, 2006
Posts: 8
Tomcat is installed in c:\dev\apache-tomcat-5.5.26.
Here is the Host container of the server.xml
<Host name="localhost" appBase="c:/dev/test"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

<Context path="/" docBase="" debug="2" reloadable="true" crossContext="true">
</Context>
</Host>

In the directory c:\dev\test\ I have the following jsp:
------- c:\dev\test\test1.jsp ----------
<%="Hello World"%>
------- End file c:\dev\test\test1.jsp ----------


In the directory c:\dev\test\test\ I have the following jsp:
------- c:\dev\test\test\index.jsp ----------
test
<br><b><%@ include file="../test1.jsp"%></b><br><br>
------- End file c:\dev\test\test\index.jsp ----------

If I browse to http://localhost:8080/test/index.jsp I get the errorrg.apache.jasper.JasperException: /index.jsp(2,7) File "/../test1.jsp" not found
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

<%@ include file="../test1.jsp"%>
This is a page-relative URL. Use a context-relative URL.
A Aflatooni
Greenhorn

Joined: May 03, 2006
Posts: 8
Context is "/". I get the same thing if I use the following:

OR

[ February 24, 2008: Message edited by: A Aflatooni ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

What happens if you hit http://localhost:8080/test1.jsp ?
A Aflatooni
Greenhorn

Joined: May 03, 2006
Posts: 8
You get the "Hello World" served. If the file is in the same directory or a subdirectory it also works. But I can't include a file in the parent directory.
Axel Brown
Greenhorn

Joined: Feb 12, 2008
Posts: 25
I think I found the solution
http://www.coderanch.com/t/87476/Tomcat/include-doesn-recognize-relative-path

I'd appreciate any input on possible security (I do not think there will be any) problems with it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't inlculde files from a parent directory in new tomcat