• 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

forward happens before service() finishes

 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When we forward request from one Servlet/JSP to other, what actually happens???

First forward happens then service() method finishes or the other way???

I guess, service() finishes after forward.

See the below code:



[ May 26, 2006: Message edited by: rathi ji ]
[ May 26, 2006: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The forward itself will not halt the execution of the service method.
For this reason, you should either branch your code so that the forward happens last or immediately follow your forward with a return statement.

The same is true with redirects.
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
The forward itself will not halt the execution of the service method.
For this reason, you should either branch your code so that the forward happens last or immediately follow your forward with a return statement.

The same is true with redirects.



Sorry Ben. I didn't get.


[ May 28, 2006: Message edited by: rathi ji ]
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
forward() is just a method call. It will not stop execution of service method. If you dont want to do anything after farward you need to use return statement.
[ May 26, 2006: Message edited by: Dilip Kumar Jain ]
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the case when sendRedirect is used instead of forward, for same code given by rathi.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vidya sagar:
What is the case when sendRedirect is used instead of forward, for same code given by rathi.



Read my earlier post.
Better yet, try it.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The flow of control in java methods does not suddenly change because you are writing servlets.
So if you call a method, it will do that method, finish it, and then continue on down through the code.

Now dealing with JSP/servlet coding, if the method call sends/commits the response (like a forward/redirect does) then you should make sure your code does not continue writing to the response, as it will raise an IllegalStateException.
As such, it is normally a good policy, after a forward/redirect to return immediately, and thus prevent problems.
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stefan Evans:
The flow of control in java methods does not suddenly change because you are writing servlets.
So if you call a method, it will do that method, finish it, and then continue on down through the code.

Now dealing with JSP/servlet coding, if the method call sends/commits the response (like a forward/redirect does) then you should make sure your code does not continue writing to the response, as it will raise an IllegalStateException.
As such, it is normally a good policy, after a forward/redirect to return immediately, and thus prevent problems.



Thanks Stefan and All.

So means my first post was right.

 
Did you just should on me? You should read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic