Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Answers Viewqa Servlet-Interview-Questions How to find a servlet object by name?

View Questions and Answers by Category


Have Programming Question? Ask it here!

Java Coder
How to find a servlet object by name?
1 Answer(s)      2 years and 10 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.

Related Tutorials/Questions & Answers: