This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes forward doubts ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "forward doubts ?" Watch "forward doubts ?" New topic

forward doubts ?

Sebastien French

Joined: Jan 04, 2012
Posts: 26


I doubt about the forward functionnality.

When forwarding from servlet 1 to servlet 2. Do we get back to servet 1 after servlet 2 complete ?

I'm allmost sure control get back to servlet 1 but ...
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper

Joined: Apr 07, 2010
Posts: 2102

Yes you will get back, but you can't really do anything any more with the response, as it is committed.

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Just to add to that a bit: that means that after you call the "forward" method in servlet 1, the code after that will indeed be executed. A lot of people seem to think that calling "forward" is like a GOTO statement, but of course it's just a Java method like all the others.

I don't know whether the code in servlet 2 will be executed before or after the code which comes after the "forward" in servlet 1, but I do know that both will be executed. (And I don't really care either -- if I did then the two servlets would be closely coupled and that would be a design problem.) And as Frits says, servlet 1 shouldn't do anything with the response after forwarding. However you're likely to want to do things like closing database connections after you forward to servlet 2.
Sebastien French

Joined: Jan 04, 2012
Posts: 26

thanks for your help
I agree. Here's the link:
subject: forward doubts ?
It's not a secret anymore!