• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

catching servlet o/p

 
Sachin Deshpande
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sachin,
A sample code in your calling sevlet which is 'Servlet A' could be

regds
maha anna
 
prabhatis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic