GeeCON Prague 2014*
The moose likes Servlets and the fly likes Servlet communication across web applications Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet communication across web applications" Watch "Servlet communication across web applications" New topic
Author

Servlet communication across web applications

Surya Kant
Ranch Hand

Joined: Mar 29, 2005
Posts: 104
Hi All,
I have two web applications running in same tomcat container.I want to communicate between two web applications using servlets.
I mean servlet1 in web application1 will call servlet2 in web application2.Is it possible??

And one more doubt is..Is session id will be same in both the web applications?


Regards,
Surya
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42056
    
  64
If by "communicate" you mean via HTTP, then you can use the HttpURLConnction class to do that. See e135 and e136 in http://www.exampledepot.com/egs/java.net/pkg.html

The session IDs will be different, because sessions are bound to web apps; they can't be shared across web apps.


Ping & DNS - my free Android networking tools app
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Or else you can also use HTTPClient for this ,

One more solution is that Obtain that ServletContext (The context name of that web application which you have defined in server.xml file) and put cross-context is true .


If you want something you never had do something which you had never done
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Or you can figure out if the reason you need to communicate is because the apps should be one? Or there's code that should be in each app?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vinod K Singh
Ranch Hand

Joined: Sep 30, 2008
Posts: 198
RaviNada Kiran wrote:One more solution is that Obtain that ServletContext (The context name of that web application which you have defined in server.xml file) and put cross-context is true .


Cross context stuff may not be portable on other servers.


My Blog
 
GeeCON Prague 2014
 
subject: Servlet communication across web applications