• 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

Difference b/w RequestDispatcher in Context and request

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Everyone,
THere are two request dispatcher, one is in Servlet Context and other in ServletRequest. Can anyone explain when do we use either one with an example
THanks
Cheers
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's very clear if you glance through the Servlet API.

If you use a ServletContext to get a RequestDispatcher you MUST use a STRING starting with a "/" which is interpreted as relative to the Web-Application root.

But if you use a Request to get a RequestDispatcher then the STRING you specify in the request.getRequestDispatcher("a STRING") CAN start with either a "/" or choose not do so.

Please note the difference in the above 2 paragraphs. MUST and CAN.

In case you are using a request to get a RequestDispatcher and you start off with a "/" then it is interpreted as relative to the Web-Apllication context just as it is with a ServletContext. But if you do not start with a leading "/" then the path is interpreted as relative to the request.(i.e /web-application/reuestURI/-----)
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

u can refer the following link

http://java.boot.by/wcd-guide/ch03s05.html

Regards
Roshini
 
reply
    Bookmark Topic Watch Topic
  • New Topic