Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

forward doubts ?

 
Sebastien French
Greenhorn
Posts: 26
Firefox Browser Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Pie
Posts: 2270
76
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
Firefox Browser Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic