Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) 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.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!