[Logo]
Forums Register Login
one servlet calling another servlet
how one servlet calls another servlet programatically ?
Can you explain your question in a little more detail?
Servlets don't call one another.

What is it you're trying to do?
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.
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
According to the javadocs, the getServlet(String) method has been returning "null" ever since Servlet API 2.1. Go with the RequestDispatcher approach.
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.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Nov 20, 2017 04:52:57.