File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "catching servlet o/p" Watch "catching servlet o/p" New topic

catching servlet o/p

Sachin Deshpande

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

Joined: Apr 06, 2001
Posts: 10
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
Sachin Deshpande

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
A sample code in your calling sevlet which is 'Servlet A' could be

maha anna

Joined: Apr 07, 2001
Posts: 18
try this .
String strUrl = URLEncoder.encode("path of ur servlet something like http:\\adress\\servlet\servletname\");
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:
subject: catching servlet o/p
It's not a secret anymore!