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

 
 


Java Coder
How to find a servlet object by name?
1 Answer(s)      a year 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>
    <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 Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.