aspose file tools*
The moose likes Servlets and the fly likes How can we call servlet from servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How can we call servlet from servlet?" Watch "How can we call servlet from servlet?" New topic
Author

How can we call servlet from servlet?

Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

It depends on what you mean by "call"


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
In HFSJ book , I read something like
A RequestDispatcher can be used to forward a request to another servlet.
but it's not shown in the book.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61008
    
  65

Have you inspected the JavaDoc for the RequestDispatcher?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5823
    
    7

Try something like this at the end of doGet or doPost:



where "/otherServlet" is the url-pattern for the target servlet.


JBoss In Action
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Originally posted by Bear Bibeault:
Have you inspected the JavaDoc for the RequestDispatcher?

OK! You ask many questions.
I looked at JavaDoc. We can only specify relative path if we have obtained the RequestDispatcher from Request.If we have obtained it from ServletContext then it has to begin with '/' and will search from current context root.
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Thanks Peter
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61008
    
  65

Exactly!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can we call servlet from servlet?