can we have communication between two servlets that are hosted on differerent host ? For example i have servlet1 on localhost and servlet2 on different localhost machine can they pass some data to each other and have some sort of communication?
The easiest way would probably be to have them communicate via HTTP, since they're already set up as web apps. The built-in java.net.URL class (and its friends URLConnection etc.) can be used for that, or for fancier stuff something like the Apache HttpComponents library.
As mentioned by Tim, there are lot of ways to invoke Servlets running on different URL. Apache HTTP Client provides different options to invoke the servlet.
Actually i am confused...i want to realize a system in such way that two web application resideing on different hosts (different machines )to pass some data to each other and communicate but in this case how will it be realised? Like i have one client-server (webapp1) on one machine and other client server(webapp 2) on another machine?
Or is it like client on one machine and server on another machine?
Can someone guide me on this?
so we have to write client+server code a both the places. Can this be realised in using servlet and tomcat server ? Can you provide some examples or source code for it?
The client would simply be Java code that makes network calls, and it would be part of each web app. In my first post I mentioned to ways to implement that. If you search for "java http client example" or some such phrase you'll find plenty of example code.
So if i setup a VM on my laptop running windows then will it be treated as different host ?
if yes then i want to have communication between two apps/servlets, one in VM and one in my laptop....also it is confusing the difference between apache tomcat and apache http server.....can you explain what exactly HTTP client needs?
So if i setup a VM on my laptop running windows then will it be treated as different host ?
Yes. You don't need a VM, though - you can run two Tomcat instances on the same machine, as long as they use different ports. Or, even easier, you can create two web apps running within the same Tomcat
it is confusing the difference between apache tomcat and apache http server
Tomcat is a servlet/JSP container written in Java. Httpd is a web server written in C that can be used as a front for Tomcat, providing capabilities that Tomcat does not have itself.
can you explain what exactly HTTP client needs?
I'm not sure what you're asking; can you rephrase the question, while giving more detail?
Actually i am not understanding the server part in servlet technology. Consider following scenario that i currently have.
I have windows system on which i have installed apache tomcat and consists of two servlets namely Servlet1 and Sevlet2. Servlet1 passes one parameter to servlet 2 so when i go to url of servlet2 on localhost, it shows that parameter. Now i have to seperate servlet1 and servlet2 say servlet1 reamains on host OS and servlet2 on windowsVM and then have same type of communication between them. What things i have to do with windowsVM like install eclipse,tomcat etc? Do we need two tomcat servers on both the hosts i.e one on VM and one on Host OS ?
mi go wrote:... Servlet1 passes one parameter to servlet 2 so when i go to url of servlet2 on localhost, it shows that parameter...
It's unclear (to me anyway) what you are wanting.
It sounds like you want to be able to share data between two servlets, regardless of whether they are being served by the same Tomcat instance or not, and regardless of whether they are running on different computing platforms (physical or virtual). You are not actually looking for a mechanism to communicate between servlets.
to get straight i am looking for mechanism that allows two servlet to communicate with each other residing on differernt hosts i.e. one on host OS(host 1) and one on VM(host 2). I am corncerned about environment setup(tomcat) and the code for the servlet.