Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Request Dispatcher

 
Ken Truitt
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The final mock examin in hf question #56 says ("xyz") is a valid argument
to getServletContext().getRequestDispatcher(). This directly contradicts
p. 204, where a 'handwritten' note says you must provide an absolute path
to the page. The mock question says that a relative path is appropriate here or something like that. What is the underlying theory?

On a related note, if a relative path is relative to the location of the request, and if the request is being dispatched from a servlet, how could
you have a 'result.jsp' in the SAME directory?

Thanks--taking test in two hours!

Ken Truitt
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ken

Good lock by the test.

It is like this : only the dispatcher obtained from the ServletRequest can accept accept a relative path, that means you may use the paths which are not starting with "\". If you use the ServletContext you must use paths which are stating whit "\".


Regards,
M
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look closer at page 204. You will see that there is no contradiction. It explains the difference between the RequestDispatcher obtained from the request and the RequestDispatcher obtained form the ServletContext.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic