Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getRequestDispatcher() clarification

 
Oricio Ocle
Ranch Hand
Posts: 284
Debian Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,
i have a doubt regarding (ServletRequest|ServletContext).getRequestDispatcher().

In the API is said that:

This method returns null if the servlet container cannot return a RequestDispatcher.


whereas in the Servlet v2.4 specs:

The getRequestDispatcher method takes a String argument describing a
path within the scope of the ServletContext. This path must be relative to the root
of the ServletContext and begin with a �/�. The method uses the path to look up
a servlet, using the servlet path matching rules in Chapter SRV.11, �Mapping
Requests to Servlets�, wraps it with a RequestDispatcher object, and returns the
resulting object. If no servlet can be resolved based on the given path, a
RequestDispatcher is provided that returns the content for that path
.


Can someone explain me why these are not contradictory?

Regards
[ September 12, 2007: Message edited by: Oricio Ocle ]
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If no servlet can be resolved based on the given path, a
RequestDispatcher is provided that returns the content for that path.


Its not necessary that the argument to the request dispatcher is always a servlet. It may be another resource like HTML files e.g.



Hence is such a scenario, the HTML page is rendered. And of course, if getRequestDispatcher cannot return a RequestDispatcher, it will return nothing(null). Please let me know if this clarifies your doubt.
 
Oricio Ocle
Ranch Hand
Posts: 284
Debian Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Satya, thanks for your reply.
the words that make me doubt are:
... content for that path

For example, it sounds to me like

will return the content of this folder to the user agent...
Dont you think it cant be misunderstanding?
 
subodh gupta
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

1)In first case the request processor will return null bcoz it found no file that RequestProccessor can return to be operated upon e.g. if you pass directory in the path.

2)but if their is path that can be resovled as a valid html content it will return the content (it can be servlet/html etc).

I think this will make you clear.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by subodh gupta:
the request processor will return null bcoz ...


subodh gupta, please use real words like "because" when posting to the forums.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah i also guess the same as what subodh gupta told.

If the particular path is leading to the actual file but NOT the directory, a non-null request dispatcher would be served with its contents.

Otherwise, a null request dispatcher (nothing) would be returned.

HtH.
[ July 23, 2007: Message edited by: Raghavan Muthu ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic