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

is it true? (about getRequestDispatcher())

 
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ServletContext.getRequestDispatcher("/MyTestServlet.do")



I want to know that the ServletContext's getRequestDispatcher() method will not take URL pattern of a servlet as a parameter?
 
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I want to know that the ServletContext's getRequestDispatcher() method will not take URL pattern of a servlet as a parameter?


Your question is not quite clear...however, if you're looking for a similar method which does not take a url-pattern as an argument....it is ServletContext.getNamedDispatcher(String ServletName) where ServletName is the name you've declared in the DD for the servlet
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MyServlet.TestSession

web.xml


RequestDispatcher rd = getServletContext().getRequestDispatcher("red");
rd.forward(request,response);


it will not work because we must pass the url starting with / to ServletContext's getRequestDispatcher() method.right?

But if want to invoke a servlet through url pattern then you must avoid the / before the url paramete.

RequestDispatcher rd = request.getRequestDispatcher("red");
rd.forward(request,response);


it works fine.
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But if want to invoke a servlet through url pattern then you must avoid the / before the url paramete.



Where do you want to avoid that? You're not supposed to avoid using "/" if you're ServletContext.getRequestDiapatcher() method.

Therefore
RequestDispatcher rd = getServletContext().getRequestDispatcher("/red");
rd.forward(request,response);
Would work fine here
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No Sayak, it will not invoke the RedServlet servlet if put "/red".

RequestDispatcher rd = getServletContext().getRequestDispatcher("/red");



Its will try to locate any resource like [Application Path]/red

Please run my code, you will get error.
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Its will try to locate any resource like [Application Path]/red


That's what it is supposed to do.... "/" means the context root(application)...By the way I ran the code with
RequestDispatcher rd = getServletContext().getRequestDispatcher("/red");
and got no errors...it's workin' fine...check if you're goin' wrong somewhere
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Sayak its working. You make my eye open. Thank you.
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the following is working:


RequestDispatcher rd = getServletContext().getRequestDispatcher("/red");



because "/red" matches pattern "/red/*" that's declared in web.xml above, right?

Or is it working because it looks in the Context and finds "red" there with disregards with the DD above?

Thanks
[ December 23, 2006: Message edited by: Firas Zuriekat ]
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The former one
[ December 23, 2006: Message edited by: Sayak Banerjee ]
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic