• 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

requestdispatcher.forward() Doubt?

 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When we call requstdisptcher.forward() from one servlet for another servlet, which HTTP method is sent GET or POST?

Moreover,

req.getRequestDispatcher("/login.html");

As this string parameter could be a call to HTML file OR it can be a call to servlet (by defining proper <servlet-mapping> in web.xml), the request will go to the container and container should recognize it as a request to an HTML file BUT i have tested this scenario with Tomcat, it first look into web.xml and calls another servlet (whose <uri-pattern> is /login.html)instead of HTML fil ?
[ March 11, 2007: Message edited by: Sandeep Vaid ]
 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When we call requstdisptcher.forward() from one servlet for another servlet, which HTTP method is sent GET or POST?

Moreover,

req.getRequestDispatcher("/login.html");

As this string parameter could be a call to HTML file OR it can be a call to servlet (by defining proper <servlet-mapping> in web.xml), the request will go to the container and container should recognize it as a request to an HTML file BUT i have tested this scenario with Tomcat, it first look into web.xml and calls another servlet (whose <uri-pattern> is /login.html)instead of HTML fil ?



answer 1 - we always do forward(request,response). The HTTP method that will be called after forward( ), depends on the HTTP method in the request object
.

answer 2 - I think you want to goto a HTML file from a serlvet. You need to check the way you obtained the 'RequestDispatcher'. if you obtained it using the getNamedDispatcher( ), the named servlet will get called. But if you get it using a getRequestDispatcher("/login.html"); then it must call the static resource. Make sure your resorce sits in webapp_root/login.html Also you ahve some differnt cases to consider if you obtain it using a HttpServletRequest or a ServletContext.

hth
 
Sheriff
Posts: 67747
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 Sandeep Vaid:
When we call requstdisptcher.forward() from one servlet for another servlet, which HTTP method is sent ...



No method is sent. A forward does not initiate a request. It merely forwards the current request to the next resource.
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya..no method is sent...

but the request object does have a property that has the value of the HTTP method..
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys i got the answer of my first query but answer to second query is still not clear..
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic