Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Use relative URL for RequestDispatcher  RSS feed

 
Himai Minh
Ranch Hand
Posts: 1566
10
  • 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: 2986
222
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!