• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between getServlet() & getRequestDispatcher()

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am confused with above two usage and their advantage over others. By doing

1) RequestDispatcher rd = getServletContext().getRequestDispatcher("/servlet/emSessionInit");
rd.forward(request,response);
and

2) emSessionInit ems = (BookDBServlet) getServletConfig().getServletContext().getServlet("emSessionInit");
ems.doPost(request,response);
My doubts are
a) What are limitations of 1 & 2, which context they can be used.
b) Can I do (2), i.e. By getting handle to servlet can i call doPost method of that servlet?
c) Is it possible to call any other method of servlet by using request dispacther object?
d) Clearly it is not possible to call servlet residing in diffrent server than the current server by 2, I am correct ?
e) When I use forward or include of RequestDispatch object what methods of calling servlet called, is it determined by what method in request object?

Sorry ... the list is big.. But if anybody can help me it would be great help for me. I think these quesion has to be answered by experts, Frank & Bill any help from you end?
Thanks once again,
reagrds,
Holla.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is one important distinction. Option 2, getServlet() simply won't work in servlet containers conforming to version 2.2 or later of the Servlet API. getServlet has been deprecated and defined to always return null, so you have to use the RequestDispatcher interface.
This only leaves your question e), and I'm not sure about that one. But check the Servlet API documentation at Sun's web site.
reply
    Bookmark Topic Watch Topic
  • New Topic