This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell 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


JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "forward doubts ?" Watch "forward doubts ?" New topic
Author

forward doubts ?

Sebastien French
Greenhorn

Joined: Jan 04, 2012
Posts: 26

Hello,

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
Bartender

Joined: Apr 07, 2010
Posts: 1686
    
  25

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

Regards,
Frits
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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
Greenhorn

Joined: Jan 04, 2012
Posts: 26

thanks for your help
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: forward doubts ?