Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

requestDispatchers forward-method equal to return???  RSS feed

 
Stefan Elfvinge
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
samplecode(somewhere in a doPost):
req.getRequestDispatcher("resource").forward(req, res)
doSth()
doSthElse()
response.sendRedirect("resource2");
I was under the impression that once forward() is called the thread of execution proceeds within "resource", but it seems like an additional thread is created and executes doSth()...which in the end causes sendRedirect to be called twice(because "resource" dispatches to the same doPost with additional data)???
Could someone please verify this?
/Steffe
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, its true.
When we have a page that redirects (or forwards or includes), we always make sure that it can only get this instruction once.
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Include is different.
you can include more than one resource from a jsp or servlet. You can also include and then forward.
"Includes the content of a resource (servlet, JSP page, HTML file) in the response. In essence, this method enables programmatic server-side includes. "
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True, but if you have a combination of forwards, includes and redirects then you're looking at a Controller and this is typically Servlet.
I realised the multiple-include after I wrote the last post, but I was lazy. Thanks for the lesson
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!