Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8850885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:00:17+00:00 2026-06-14T13:00:17+00:00

Does RequestDispatcher work over multiple webapps ? I’m asking because I had a single

  • 0

Does RequestDispatcher work over multiple webapps ?

I’m asking because I had a single webapp working fine that uses RequestDispatcher rather than redirects so state isnt lost when displaying error and feedback messages.

However I now need to split some functionality between two webapps, so initial call is made from a webpage hosted on webapp1, calls webapp2 which eventually returns user to a page hosted on webapp1.

Clearly if webapps and webapp2 were on different websites using RequestDispatcher would not be possible but is it if both webapps are deployed within the same instance of a servlet container (tomcat 7)

Update

Got the request dispatcher part to work as explained in answer but am unable to retrieve data put in my webapp2 which iss why Im using it

i.e

webapp2 called , does some processing and then dispatches to a jsp on webapp1

protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
{

    HttpSession userSession = request.getSession(true);
    String emailAddress = ......
    String nextPage     = /finish.jsp
    userSession.setAttribute("DATA", emailAddress);
    ServletContext otherContext = getServletContext().getContext("/webapp1");
    otherContext.getRequestDispatcher(nextPage).forward(request, response); 
}

webapp2 jsp file contains

...
<p>Email(<%=((String)session.getAttribute("DATA"))%>)</p>
...

but always displays null

Update 2 **

Im wondering if Im misunderstanding what crossContext=”true” actually does . Does it make the same HttpSession availble in different webapps, or does it just make the ServletContext from one webap availble to another and hence allow one webapp to see the HttpSessions of another webapp ?

Im starting to think what Im doing is a bad idea as Ive always been keen to use vanilla servlet setups and never want to tie myself to a particular implementation. I think it might help if I explain why I flet the need to split the webapps in the first place.

I had a one webapp (webapp1), that was a website about a product I develop and code for purchasing that product using Google Checkout (now Google Wallet).

I then added created a new webapp for a new product (webapp2).

I then tried to add Google Checkout for new product into webapp2, but realised I couldnt do this easily because Google Checkout requires me to provide it with a url which it can call by application once it has processed payment so that I can then send
user a license. The url was already set to a servlet in webapp1, but
it wouldn’t make sense for webapp1 to process payment s for product 2.

One option was to merge webpp1 and webapp2 into one webapp, but this goes against my general view of keeping things modular, it
would also mean evey time I would want to make chnages for one
product Id have to redeploy everything. It also meant big
modifications to webapp1 which I really didnt want to modify as it
was working and stable.

The alternative was to create webapp3 and then google url can point to this, and use this for processing purchases of product 1
and product 2 which is what Ive done. But the problem is when
purchasing product 1 the starting page is in webapp1 , and once
purchase has taken place I want to go back to a page in webapp1, but
only webapp3 has the details of the user who has just made the
purchase which I wanted to display on on the page in webapp1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:00:19+00:00Added an answer on June 14, 2026 at 1:00 pm

    This is due to security reasons by default not possible. You first need to configure Tomcat to enable exposing the ServletContext of the current webapp to other webapps. This is to be done by setting the crossContext attribute of context.xml to true.

    <Context ... crossContext="true">
    

    Once done that, then you can use ServletContext#getContext() to obtain the other servlet context by its context path and finally use the RequestDispatcher as obtained by ServletContext#getRequestDispatcher() the usual way as you would do on the one obtained by HttpServletRequest#getRequestDispatcher().

    E.g.

    ServletContext otherContext = getServletContext().getContext("/otherContext");
    otherContext.getRequestDispatcher("/WEB-INF/some.jsp").forward(request, response);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how to get IntelliSense to work reliably when working in C/C++
Does the G'MIC (Grey's Magic Image Converter) library work on iOS ? what steps
Does doxygen doesn't work properly on python script with a shebang? I tried one
I have a servlet that does a request dispatcher include of another servlet. The
does anyone know if iOS Simulator (that goes with XCode) support any kind of
The question is in the title: Does <jsp:forward> or RequestDispatcher.forward use GET or POST
Does anyone know how I can implement a single Touch Event. A simple, one
Does anyone know of a Mootools script that provides nested sortable but also works
Does anyone know of any resources that talk about best practices or design patterns
Does anyone know of a Ruby module that will take an integer and spell

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.