Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Context root

 
Rahul Jadaun
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose you have a servlet - com.whiz.ControllerServlet and you need to create a request dispatcher to it using servlet context.

context.getRequestDispatcher("/ControllerServlet") is correct?

When you say that req dispatcher from a context should start from context root, should it not be '/com.whiz.ControllerServlet'?
What exactly is the context root?
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
context root is the root directory of web application i.e. parent directory of WEB-INF, so it will be "/"

'com.whiz.ControllerServlet' is the servlet class's fully qualified name. Access the servlets using the URL mapping defined in web.xml
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
context.getRequestDispatcher("/ControllerServlet") is correct?


i guess, if you want to forward to a servlet you should use the
getNamedDispatcher( )
here is what the spec says -

The getNamedDispatcher method takes a String argument indicating the
name of a servlet known to the ServletContext. If a servlet is found, it is wrapped with a RequestDispatcher object and the object is returned. If no servlet is associated with the given name, the method must return null.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic