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

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

Advertisement
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>
    <servlet-name>MyServlet</servlet-name>
    <servlet-class>roseindia.MyServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name> MyServlet </servlet-name>
    <url-pattern>/ MyServlet </url-pattern>
  </servlet-mapping>

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:
Advertisements