Meaningless Drivel is fun!*
The moose likes Tomcat and the fly likes After I've configured Apache+Tomcat, WEB-INF cannot be accessed from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "After I Watch "After I New topic
Author

After I've configured Apache+Tomcat, WEB-INF cannot be accessed from JSP

Sergey Kargopolov
Ranch Hand

Joined: Jul 04, 2003
Posts: 63
Hello!

I am having a situation which I cannot understand and resolve.

I have configured Apache+mod_jk+Tomcat. Apache Web server hosts PHP web sites only and Tomcat hosts JSP web sites only. Almost everything works well but jsp:include stoped working properly!!!


Using VirtualHosting I configured:

domain_1.com - is processed by Apache
domain_2.com - is processed by Tomcat(both static content and JSP/Servlets)

In domain_2.com JSP is working well, Servlets are working well. But jsp:include stoped working properly!!!

For example:
index.jsp includes siteMenu.jsp

<jsp:include page="WEB-INF/siteMenu.jsp"/>----- this works well!

but other pages located in subfolders cannot access WEB-INF

<jsp:include page="../WEB-INF/siteMenu.jsp"/>----- does not work. Cannot find the file..
and
<jsp:include page="/WEB-INF/siteMenu.jsp"/>----- from subfolders does not work ....

But if I access web sites using Tomcat only - not via Apache and mod_jk, then the Web site is working properly and all pages are included properly. No code modification needed.

Please advised me what did I configure wrong? How to fix this?


#worker.properties file
workers.tomcat_home=/mnt/ebs/apache-tomcat-6.0.14
workers.java_home=/usr/java/jdk1.6.0_21
worker.list=ajp13

worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13

#server.xml

<Host name="www.domain_2.com" appBase="webapps/domain2"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/" docBase="/mnt/ebs/apache-tomcat-6.0.14/webapps/domain2"/>
</Host>


# Configure mod_jk in httpd.conf
#
LoadModule jk_module /etc/httpd/modules/mod_jk.so
JkWorkersFile /mnt/ebs/apache-tomcat-6.0.14/conf/worker.properties
<VirtualHost *>
DocumentRoot "/mnt/ebs/apache-tomcat-6.0.14/webapps/domain2"
ServerName "www.domain_2.com"
DirectoryIndex index.jsp
JkMount /* ajp13
</VirtualHost>

Thank you!

Sergey Kargopolov
Ranch Hand

Joined: Jul 04, 2003
Posts: 63
Tried using ajp instead of mod_jk to see the difference and now I am getting an error message:

You do not have permission to access / on this server

<VirtualHost *>
DocumentRoot "TOMCAT/webapps/domain_2"
ServerName "www.domain2.com"
DirectoryIndex index.jsp
ProxyPreserveHost On

ProxyPass /* ajp://localhost:8009
ProxyPassReverse /* ajp://localhost:8009

<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
Sergey Kargopolov
Ranch Hand

Joined: Jul 04, 2003
Posts: 63
Has anyone come across this situation? please advise me... Where is mistake? What do i do wrong? I read Tomcat 6 documentation and searched the web for examples of integration Apache with Tomcat and it looks to me that I did the integration correctly. If the above mentioned configuration is correct then why would JSP be not able to include other JSP pages from upper directories?

I double checked!!! If I use mod_jk and Apache as front server then JSP can include any other JSP pages from sub directories. But cannot include any other JSP from upper directories.

<jsp:include page="WEB-INF/siteMenu.jsp"/>----- this works well!
<jsp:include page="inc/siteMenu.jsp"/>----- this works well!

<jsp:include page="/WEB-INF/siteMenu.jsp"/>----- does not work!
<jsp:include page="../WEB-INF/siteMenu.jsp"/>-----does not work!
<jsp:include page="../inc/siteMenu.jsp"/>-----does not work!

But if I access JSP web application with Tomcat as Stand along then jsp:include works properly and no problems appear.

Please advise me how to resolve this situation.?

Thank you!

Thank you.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4165
    
  21

This almost definitely has to do with a path issue. You think the relative URI is coming from the File Path, so "/WEB-INF/" would mean '/mnt/ebs/apache-tomcat-6.0.14/webapps/domain2/WEB-INF/' but it is likely coming from the web URL, 'http://www.domain_1.com/WEB-INF/'. So when you try to use the JSP include, don't do it relative to the file you are at, but do it relative to the URL the browser is at. See if that helps.


Steve
Sergey Kargopolov
Ranch Hand

Joined: Jul 04, 2003
Posts: 63
Hi Steve!

Thank you very much for your reply!

What you are suggesting makes perfect sense. Here is what I have tried. Please have a look if I am getting you correctly.

The location of the page that includes "siteMenu.jsp" is at www.doman2.com/photo/index.jsp

Here is what I've tried:

<jsp:include page="'/mnt/ebs/apache-tomcat-6.0.14/webapps/domain2/WEB-INF/inc/siteMenu.jsp"/> -- Does not work
<jsp:include page="http://www.domain2.com/WEB-INF/inc/siteMenu.jsp"/> -- Does not work

Then I tried using @ include and got an error message:

<%@ include file="../WEB-INF/inc/siteMenu.jsp" %>

org.apache.jasper.JasperException: /photoView.jsp(61,3) File "/../WEB-INF/inc/siteMenu.jsp" not found


Steve, what am I doing wrong?


Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4165
    
  21

<jsp:include page="http://www.domain2.com/WEB-INF/inc/siteMenu.jsp"/>

This is the route you will probably have to take. The problem is that you can not access the WEB-INF directory outside the web app it belongs to. What happens when you move the /inc/siteMenu.jsp out of the WEB-INF and into the base directory (or some non-WEB-INF subdirectory)

Something like
<jsp:include page="http://www.domain2.com/menus/inc/siteMenu.jsp"/>



I am actually out of my league at this point though. I think this is correct, but it has been over a year since I have touched a web application...
Sergey Kargopolov
Ranch Hand

Joined: Jul 04, 2003
Posts: 63
I have tried that Steve!

In fact when I move the siteMenu.jsp to the same directory level as pages that include it or into a subdirectory then <jsp:include> works properly.

So, if I make a copy of siteMenu.jsp and place it on the same directory level then this works!

<jsp:include page="siteMenu.jsp"/>

When I move siteMenu.jsp into a subdirectory then it also works!

<jsp:include page="inc/siteMenu.jsp"/>

but when I place siteMenu.jsp to an upper level directory then it stops working...

<jsp:include page="../inc/siteMenu.jsp"/> or <jsp:include page="/inc/siteMenu.jsp"/> do not work!


I need siteMenu.jsp to be located in one upper directory or WEB-INF so that any page of web application can access it from any directory.

This behavior is only when requests are directed to JSP web application via Apache mod_jk. If I open web application in Tomcat as Stand along container/web server. Then jsp:include works properly and includes files from upper or lower level directories no problem.

Any thoughts?

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: After I've configured Apache+Tomcat, WEB-INF cannot be accessed from JSP
 
Similar Threads
Apache 2.0.53 + Tomcat 5.5.7 integration on Windows using mod_jk
How to create a multiple tomcat instances in windows?
mod_jk tries to map every request from apache
DNS + Apache + Tomcat
File uploading problem