Click to See Complete Forum and Search --> : Servlet Servlet communication


Monika
May 4th, 2000, 04:07 AM
How to send data(values in variables) from servlet1 to servlet2?
& how to read data from servlet2 sent by servlet1?

kib63613
May 4th, 2000, 05:04 AM
Suppose that you have two servlet, servletA and servletB. These two servlet have been initialized
in the servlet context. Suppose that servletA want to access the data in the servletB It can get the
servletB via ServletContext and access the data in the servletB. You may consider the following
code snippet :

ServletContext context = getServletContext();
ServletB servletb = (servletB)context.getServlet("servletB");
String some_data = servletb.getSomeData();
System.out.println("some data is : " + some_data);



I never try this code snippet.
For more information, you may consider the content in the Java Server Programming by wrox,
or Java Servlet Programming by oreilly.
good luck,
Alfred Wu

salandri_s
June 10th, 2000, 11:59 AM
Hi Monika,

You may use Servlet Chaining Mechanism (and read Header Names and Header in 2nd servlet) for Chaining Output from 1st Servlet to 2nd one and so on.

C Servlet Programming by Karl Moss for more details and sample code.

Srinivas,
Columbus

vasgaddam
June 12th, 2000, 07:43 AM
Hi, U can do in this way, if ur sending 1 or 2 variables..
If this is ur form in servlet1.. then,
form name="" method="" action="http://localhost:8080/servlet/Servlet2?Name=value&Name2=value2...
And in ur servlet2, access these values by,
String str1 = req.getParameter("Name");
String str2 = req.getParameter("Name2");

Hope this will help u

Sreeni