Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
A Aflatooni
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The solution is to avoid page-relative addressing and to use context-relative addressing.
 
A Aflatooni
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is context-relative includes that I get an error on.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please include your web app structure and the paths that you are using.
 
A Aflatooni
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ include file="../test1.jsp"%>
This is a page-relative URL. Use a context-relative URL.
 
A Aflatooni
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you hit http://localhost:8080/test1.jsp ?
 
A Aflatooni
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic