wood burning stoves 2.0*
The moose likes Servlets and the fly likes how to call servlet from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to call servlet from servlet " Watch "how to call servlet from servlet " New topic
Author

how to call servlet from servlet

Anthony Karta
Ranch Hand

Joined: Aug 09, 2004
Posts: 342
hi all,

how to call servlet from servlet as if we invoke it from browser.

what I want to do is like this:

ServletA
ServletB

each servlet is independent and generates XML element (JDOM object btw)

NewServlet:
Call ServletA, cache its XML into Jdom element
Call ServletB, add its XML into Jdom element

thanks all
tony


SCJP 5
Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Hi Tony,
I think you can try using getNamedDispatcher in ServletContext.

Correct me if I am wrong..
Hope this help...

daniel
Vijayendra V Rao
Ranch Hand

Joined: Jul 04, 2004
Posts: 195
You can use redirect. Do whatever processing that you need to do in your first servlet and then you can redirect the control to your second servlet (by specifying the URL) and then complete the remaining processing.

Go through the Servlet Response API. I think the API should help.


Vijayendra <br /> <br />"The harder you train in peace, the lesser you bleed in war"
Anthony Karta
Ranch Hand

Joined: Aug 09, 2004
Posts: 342
thanks for your reply.
but I don't think redirect will work because I dont want to move to other servlets, just want to call them.

I know we should encapsulate the business logic into bean but it is a huge application and hard to change.

thanks
tony
 
wood burning stoves
 
subject: how to call servlet from servlet