• Post Reply Bookmark Topic Watch Topic
  • New Topic

Use relative URL for RequestDispatcher

 
Himai Minh
Ranch Hand
Posts: 1400
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On p. 146 of Charles Lyon's book,

Which methods on which interfaces can be used to obtain a RequestDispatcher for a relative URL? (choose two)
...
B. getRequestDispatcher(String) on ServletContext
..
D.getRequestDispatcher(String) on ServletRequest
E.getRequestDispatcher(String) on HttpServletRequest


I think there should be three answers : B,D,E.
But the given answers are only D,E.

According to ServletContext API, the ServletContext.getRequestDispatcher(url).

ServletContext "
The pathname must begin with a / and is interpreted as relative to the current context root


 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 2785
175
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The pathname must begin with a / and is interpreted as relative to the current context root

This is relative to the current context root but not relative to the current Servlet (from where the requestDispatcher is gotten). That is why B is not correct.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!