This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes ServletContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "ServletContext" Watch "ServletContext" New topic
Author

ServletContext

thamara chempakam
Greenhorn

Joined: Jul 09, 2007
Posts: 20
Hi Ranchers,
How one ServletContext can communicate with the another ServletContext.

thanks in advance
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

There are several ways.

What are you trying to acomplish?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
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

Joined: Jan 10, 2002
Posts: 60783
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
thamara chempakam
Greenhorn

Joined: Jul 09, 2007
Posts: 20
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Jul 09, 2007
Posts: 20
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

Joined: Dec 11, 2004
Posts: 13410

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

    Joined: Jul 09, 2007
    Posts: 20
    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

    Joined: Dec 11, 2004
    Posts: 13410

    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

    Joined: Apr 20, 2006
    Posts: 3344

    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.


    Everything has got its own deadline including one's EGO!
    [CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
    Ben Souther
    Sheriff

    Joined: Dec 11, 2004
    Posts: 13410

    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

    Joined: Apr 20, 2006
    Posts: 3344

    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.
     
    Don't get me started about those stupid light bulbs.
     
    subject: ServletContext
     
    Similar Threads
    Obtain ServletContext from Request
    ServletContext
    full path
    Class or interface
    What is the name of the object that is created/maintained by the Servlet Container and contains all