Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Correct answer

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
11.Which of the following are correct statements. Select the two correct answers.

A.The getRequestDispatcher method of ServletContext class takes the full path of the servlet, whereas the getRequestDispatcher method of HttpServletRequest class takes the path of the servlet relative to the ServletContext.
B.The include method defined in the RequestDispatcher class can be used to access one servlet from another. But it can be invoked only if no output has been sent to the server.
C.The getRequestDispatcher(String URL) is defined in both ServletContext and HttpServletRequest method
D.The getNamedDispatcher(String) defined in HttpServletRequest class takes the name of the servlet and returns an object of RequestDispatcher class.


I feel the answer is c&d but the answers are a&c.Can anyone explain?
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answes c & d are correct.
a is not currect, as can be verified from the apis.
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no getNamedDispatcher(String) defined in HttpServletRequest class, hence D is incorrect.

getRequestDispatcher(String URL) is found in both ServletContext and HttpServletRequest, hence C is correct.

The include method defined in the RequestDispatcher class can be invoked even if response has been committed (unlike forward). include() does not throw an IllegalStateException even if the response was already committed.
Hence B is incorrect.

a is not currect, as can be verified from the apis


Are you sure referring the official J2EE APIs?

ServletContext::getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path)
The pathname must begin with a "/" and is interpreted as relative to the current context root.


Hence A is correct.
 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"The getRequestDispatcher method of ServletContext class takes the full path of the servlet"

I feel this part is not correct,as it doesnt take the full path
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Full path means context level path, or say it root level path that begins
with "/".

Straight from Java� Servlet Specification
Version 2.4



The getRequestDispatcher method takes a String argument describing a
path within the scope of the ServletContext. This path must be relative to the root of the ServletContext and begin with a �/�.




To allow RequestDispatcher objects to be obtained using relative paths that
are relative to the path of the current request (not relative to the root of the ServletContext), the getRequestDispatcher method is provided in the
ServletRequest interface.



Thanks,
 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks I got it
 
reply
    Bookmark Topic Watch Topic
  • New Topic