How to find a servlet object by name?


Share on Google+Share on Google+

Java Coder
How to find a servlet object by name?
1 Answer(s)      5 years and 9 months ago
Posted in : Servlet Interview Questions

How can we locate a servlet object in the code by it's object name?

View Answers

May 11, 2012 at 1:11 PM

A. In web.xml you map servlet and define url pattern. Now this url-pattern is used for calling servlet.

    <servlet-name> MyServlet </servlet-name>
    <url-pattern>/ MyServlet </url-pattern>

A Servlet can get a list of all other Servlets in the Servlet Context by calling getServletNames on the ServletContext object. ServletContext is available through the ServletConfig object's getServletContext method. After obtaining the reference to another Servlet that Servlet's methods can be called.



Advertisement null