Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletContext

 
thamara chempakam
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,
How one ServletContext can communicate with the another ServletContext.

thanks in advance
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several ways.

What are you trying to acomplish?
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each web application has one and only one ServletContext. There is no such thing as one ServletContext communicating with another ServletContext. This would be the same as one web app communicating with another web app. You can use the ServletContext to pass objects (and init parameters called context initialization parameters) between 2 Servlets that exist in the same web app.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Ku:
There is no such thing as one ServletContext communicating with another ServletContext.


You are mistaken. But we'll wait until we find out what the OP is actually trying to do before commenting further.
 
thamara chempakam
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

Each web application has one and only one ServletContext. thats right.
But how one ServletContext(one Web Application) communicate with another ServletContext (another web application).

thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, there are several ways.
I'm not going to try to list them.

If you tell us what you're trying to accomplish, someone can probably suggest a good say to do it.
 
thamara chempakam
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

i have two web application (running on two different Tomcat). i want to call one method of wepApp1 from webApp2. how can it be possible?

thanks and regards
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Web applications don't have methods.

Without some details about what you're trying to accomplish, we can't give you details about how to do it.

Again, there are several ways for web applications to communicate with one another.
Some of them include:
  • RMI
  • HTTP Posts
  • Hyperlinks with querystrings.
  • Web services
  • Shared files
  • A shared database
  • JMS

  • There are more but those are the ones I can think of off the top of my head.
     
    thamara chempakam
    Greenhorn
    Posts: 20
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Ben,

    The dirctory structure of webApp1 is given below


    In web2, instead of Manage.java i have a class offload.java which wants to call the Manage.method().
    how will it be possible

    [BPSouther: Added code tags]
    [ July 26, 2007: Message edited by: Ben Souther ]
     
    Ben Souther
    Sheriff
    Posts: 13411
    Firefox Browser Redhat VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If this were my issue and there were a lot of them, I would look at a product like Apache Axis to expose these methods as webservices.

    If it were one or two, and they were fairly simple, I would probably just write a servlet that exposes the methods and then use either java.net.URLConnection or a library like Jakarta Commons httpclient to build the client on the other end.

    I'm not an expert on JMS or RMI but you might want to look into those as well.
     
    Raghavan Muthu
    Ranch Hand
    Posts: 3381
    Mac MySQL Database Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I know that webservice provides you the facility for the exposing the services outside.

    Is it not possible to communicate within web applications without going for webservices or any other external features but using Servlet's features Ben?

    I think it will make sense to use Servlet's features (like ServletContext etc) only for the interaction within the same web application. Is that right?

    Just to confirm my thought on the same.
     
    Ben Souther
    Sheriff
    Posts: 13411
    Firefox Browser Redhat VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Raghavan Muthu:
    I know that webservice provides you the facility for the exposing the services outside.

    Is it not possible to communicate within web applications without going for webservices or any other external features but using Servlet's features Ben?

    I think it will make sense to use Servlet's features (like ServletContext etc) only for the interaction within the same web application. Is that right?

    Just to confirm my thought on the same.


    Yes, Tomcat (and most other servers, I assume) can be configured to allow some crossContext interaction.
    In this case, however, the original poster has already stated that the two applications are running on different instances of Tomcat.
    [ July 26, 2007: Message edited by: Ben Souther ]
     
    Raghavan Muthu
    Ranch Hand
    Posts: 3381
    Mac MySQL Database Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    In case of interaction between the two applications on a different instances of Application Server, the only possible way to proceed is to rely on the external features like WebServices etc.

    Thank you Ben.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic