File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to call servlet from servlet
 
Similar Threads
Servlet Chaining help
Know which servlet is sending the request
Mapping a main Action Servlet to other servlets
RequestDispatcher.forward to another servlet to handle form in doPost?
Do we return to the redirecting servlet after response.sendRedirect