Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

getRequestDispatcher() clarification

 
Ranch Hand
Posts: 284
Netbeans IDE Firefox Browser Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Firefox Browser Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67636
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic