File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlet - Servlet Communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet - Servlet Communication" Watch "Servlet - Servlet Communication" New topic

Servlet - Servlet Communication

jaya sudha

Joined: Jun 18, 2004
Posts: 20

How to do Servlet - Servlet Communication..
How to call a servlet from a servlet
Please help me .........

Frank Carver

Joined: Jan 07, 1999
Posts: 6920
How to do Servlet - Servlet Communication..
How to call a servlet from a servlet

These are two quite different questions. I hope you were expecting different answers.

To communicate between servlets you typically use the "application context" ( returned by getServletContext() ). Any objects placed as attributes in this context will be visible to all servlets and JSPs in an application.

To call a servlet from another servlet is more complex to answer. It largely depends whet you mean by "call a servlet". You can return an HTTP page to the browser which makes a redirect request to the new servlet, you can use a client API (I usually use HTTPUnit, but there are plenty of others) to make an HTTP call to the other servlet. You can forward the current HTTP request to the other servlet by obtaining a RequestDispatcher, etc..

Can you explain a bit more about what you want to do with this?

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
wood burning stoves
subject: Servlet - Servlet Communication
It's not a secret anymore!