Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to use ServletContext.getContext to request servlet in another webapp??

843840Sep 1 2010 — edited Sep 9 2010
I have two webapps on tomcat, on my vps. So as an example, I have maindomain.com and secure.maindomain.com under the webapps folder.

I was reading online this morning an article about the server.xml file, because I've been looking for an answer to this question -
How do you call a servlet from one domain (webapp) within a subdomain (another webapp). The article mentioned the attribute crossContext which is placed within the <Context> attribute.
I updated my server.xml file, adding crossContext, and then restarted Tomcat on my vps.

I setup a test page on the subdomain called hello.jsp. It contains the following test code.
<% ServletContext ctx = this.getServletContext().getContext("/"); 
   String myUrl = "maindomain.com/Customers/go.test1"; 
   RequestDispatcher dispatcher = ctx.getRequestDispatcher(myUrl); 
   
   dispatcher.include(request, response); %>
I have tried many combinations, in putting different values for the getContext() method and the myUrl variable. But have proven to be unsuccessful.

Here is a snippet of my server.xml file.
<Host appBase="webapps/maindomain.com" name="maindomain.com" unpackWARs="true" autoDeploy="true">

<Context path="" docBase="" debug="0" reloadable="false" crossContext="true">     

<!-- servlets that I want to access from subdomain are contained in this path -->

<!-- Resource params specified here -->

</Context>


<Context path="/Customers" docBase="Customers" debug="0" reloadable="false" crossContext="true">

<!-- servlets that I want to access from subdomain are contained in this path -->

<!-- Resource params specified here -->

</Context>

</Host>

<Host appBase="webapps/secure.maindomain.com" name="secure.maindomain.com" unpackWARs="true" autoDeploy="true">

<Context path="" docBase="" debug="0" reloadable="false">    

<!-- Resource params specified here -->

</Context>

</Host>
Can someone please direct me as to what I'm doing wrong here? I know I am missing something...or perhaps my syntax/params in my test jsp page are not correctly matching what I have in my server.xml file....???
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 7 2010
Added on Sep 1 2010
8 comments
1,789 views