• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Understanding problem in RequestDispatcher

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am having some understanding problem.
The following is from SRV.8.1

To allow RequestDispatcher objects to be obtained using relative paths that
are relative to the path of the current request (not relative to the root of the
ServletContext), the getRequestDispatcher method is provided in the
ServletRequest interface.
The behavior of this method is similar to the method of the same name in the
ServletContext. The servlet container uses information in the request object to
transform the given relative path against the current servlet to a complete path. For
example, in a context rooted at ’/’ and a request to /garden/tools.html, a request
dispatcher obtained via ServletRequest.getRequestDispatcher("header.html")
will behave exactly like a call to
ServletContext.getRequestDispatcher("/garden/header.html"
).



I could not understand the (underlined)example of relative path given. The request dispatcher is called from a servlet then how can the request be /garden/tools.html. Should it not be like /garden/tools.do where tools.do is the servlet mapping to the servlet having requestDispatcher.

Also i could not understand another thing. In specification it is written:

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
.



What is meaning of underlined text.
But the API says that getRequestDispatcher() method returns null if the servlet container cannot return a RequestDispatcher.

---Thanks and Regards.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the first case you are thinking it right. Generally RequestDispatcher is obtained in servlets so that path should look like a servlet path. But remember that I can map a servlet to the path /garden/tools.html or even it it is a static resource, I can put a filter on that path and that filter might obtain the RequestDispather on the request object. So we can't say that the example is wrong.

In the second case, what the spec means that if suppose I call RequestDispacher on the path /pages/myPage.html, then first the container will look if any servlet is mapped on that path, if there is no servlet mapped to that path, then a request dispatcher for the actual HTML page named myPage.html in the pages directory will be returned. If there is no myPage.html in pages directory, then null will be returned...
 
Abhilasha Sharma
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.I got it.
Thanks Ankit.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic