Two Laptop Bag*
The moose likes Servlets and the fly likes catching servlet o/p 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 "catching servlet o/p" Watch "catching servlet o/p" New topic
Author

catching servlet o/p

Sachin Deshpande
Greenhorn

Joined: Jan 31, 2001
Posts: 25
I have a servlet A which calls another servlet B. B throws an html o/p. how can servlet A catch the o/p sent by servlet B?
nirmal baba
Greenhorn

Joined: Apr 06, 2001
Posts: 10
Hi
U will have to use the RequestDispatcher's include(req,res) method in the calling servlet(servlet A in ur case) which then will include the output of the called servlet(servlet B in ur case) at the point of inclusion!!
Only thing that u have to keep in mind that u should use version2.1 and later (since RequestDispatcher got introduced in 2.1 only) for ur servlet class files to compile successfully
Kindly keep me informed if this explanation helped u sort out ur problem!!
Wish u all the best
Nirmal
Sachin Deshpande
Greenhorn

Joined: Jan 31, 2001
Posts: 25
Do I have to add data(or an object) that i want to pass in the req obj?
and then do i just call B by the sendRedirect method as I have been doing???
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Sachin,
A sample code in your calling sevlet which is 'Servlet A' could be

regds
maha anna
prabhatis
Greenhorn

Joined: Apr 07, 2001
Posts: 18
try this .
String strUrl = URLEncoder.encode("path of ur servlet something like http:\\adress\\servlet\servletname\");
try
{
URL u = new URL(strUrl);
InputStream i = u.openStream();
//now u have inputstream .. u can u anything u like ...
}
catch(Exception e)
{}
hope it might help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: catching servlet o/p
 
Similar Threads
advantages of EJB
Java - OOPS
Basics Doubt
Question for Chris Richardson : what do you call POJOs ?
Shift Operator