Results 1 to 5 of 5
  1. #1
    richip is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default Inter-Servlet Communication

    I have a requirement to have one servlet call a method on another servlet and be able to pass (in order of preference) either any object, any Serializable object or any JavaBean from the caller to the callee and return same. Could you please provide suggestions on good ways to accomplish this?

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Inter-Servlet Communication

    You can place your object in the HttpServletRequest attribute using the setAttribute() method and then forward it to another servlet using a RequestDispatcher.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,422
    Rep Power
    20

    Default Re: Inter-Servlet Communication

    Moved from Advanced Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    richip is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default Re: Inter-Servlet Communication

    Quote Originally Posted by wsaryada View Post
    You can place your object in the HttpServletRequest attribute using the setAttribute() method and then forward it to another servlet using a RequestDispatcher.
    Thanks for the reply. After your suggestion, I read up on RequestDispatcher and from what I've read, it seems requests and responses can only be forwarded to/included from the same web application. There's an additional limitation in that the two (or more) servlets I was referring to might be in different web applications (though still on the same server). Correct me if I'm wrong, but RequestDispatcher can only invoke other resources within the same context so another web application seems out of the question.

    Did I understand RequestDispatcher correctly? Any other suggestions?

  5. #5
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Inter-Servlet Communication

    Yes, the RequestDispatcher will work when the resource in the same web application only. But if the other application is in the same application server you can access the other context and get their RequestDispatcher. You might try something like:

    Java Code:
    ...
    request.getServletContext().getContext("/anothercontext").getRequestDispatcher("/someservlets");
    ...

Similar Threads

  1. Servlet communication
    By narcissist in forum Java Servlet
    Replies: 4
    Last Post: 12-20-2010, 06:52 PM
  2. tomcat + inter-process communication?
    By justinschw in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 03-15-2010, 09:57 PM
  3. applet servlet communication
    By viswamadhavi in forum Java Applets
    Replies: 0
    Last Post: 04-06-2009, 02:12 PM
  4. inter process communication
    By ibtehal in forum Networking
    Replies: 5
    Last Post: 06-23-2008, 02:35 AM
  5. applet servlet communication
    By hardc0d3r in forum Java Applets
    Replies: 1
    Last Post: 07-12-2007, 07:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •