Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

requestdispatcher.forward() Doubt?

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • 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 ]
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Guys i got the answer of my first query but answer to second query is still not clear..
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic