Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Forward between Web Apps - How To?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider there are two servlets, Servlet1 under WebApp1 and Servlet2 under WebApp2 deployed in two different JVMs.
I need to forward the request from Servlet1 to Servlet2, How to implement this in code?

Note: I need the request and response objects - So response.redirect() doesnt solve my problem.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is dangerous and I've never seen it done correctly. It's possible, but you attempt it at your own risk.

You may need to change the configuration depending on your container. Cross-context communication is typically disabled by default as it could pose a security risk if one application is malicious.

You can reach from context to another using getServletContext().getContext(contextName), you can then get the request dispatcher and forward as normal. Whether or not it works is a matter of chance

One problem you may encounter is that crossing from one context to another may re-enter through the thread pool, so if you are doing an include you have no control over the ordering of the two included resources! There's more to this but it is too vendor specific to warrant discussion. As I said, dangerous and hard to get right.
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have not done this, so I am not sure this will work.

But couldn't you use the method java.servlet.ServletContext.getContext(String uripath) to return the ServletContext of WebApp2, then use the ServletContext2 and wrap the path of Servlet2 in a RequestDispatcher, and then forward the current request and Response objects to Servlet2.





I guess David, beat me to the response.
[ September 22, 2005: Message edited by: Craig Jackson ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic