• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

https://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.
 
Sheriff
Posts: 67752
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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is context-relative includes that I get an error on.
 
Bear Bibeault
Sheriff
Posts: 67752
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
Please include your web app structure and the paths that you are using.
 
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
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 error:org.apache.jasper.JasperException: /index.jsp(2,7) File "/../test1.jsp" not found
 
Bear Bibeault
Sheriff
Posts: 67752
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

<%@ 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67752
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
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
Sheriff
Posts: 67752
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
What happens if you hit http://localhost:8080/test1.jsp ?
 
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
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.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I found the solution
https://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.
 
We can walk to school together. And we can both read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic