• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

one servlet calling another servlet

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how one servlet calls another servlet programatically ?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you explain your question in a little more detail?
Servlets don't call one another.

What is it you're trying to do?
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would guess the RequestDispatcher is what you're looking for - it's the closest thing towards having one servlet "invoke" another (i.e. pass request handling to another). There's no way (indeed there is no need) to invoke a servlet instance directly. Please clarify for further advice.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javax.servlet.http.HttpServlet servlet1 = (javax.servlet.http.HttpServlet)getServletContext().getServlet("servlet2");
servlet1.doGet(req, res);

where servlet2 is the name given in web.xml file
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to the javadocs, the getServlet(String) method has been returning "null" ever since Servlet API 2.1. Go with the RequestDispatcher approach.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please bear in mind, though, that getting one servlet to call another is like going out into the street and knocking on your own front door just to ask someone to pass the salt.

As a reality check, ask yourself what the servlet you are calling actually does, and if you can make that behaviour available to both servlets by something like s simple method call.
reply
    Bookmark Topic Watch Topic
  • New Topic