apache > cocoon

- Home

# Advanced Control Flow

## Cocoon and continuations

With continuations in the language, you can essentially store the continuation of `sendPageAndWait()` (think of all the stack trace, and the program counter), put it in a global hash table associated with an id. The id is then encoded in the `response.xml` page as an URL. When the user clicks on that URL, on the server side the associated continuation is resumed. Resuming the processing happens as if nothing was stopped, you get all the stack trace back, and all the local variables.

So instead of using beans to store things in session, you use normal variables in a program. Since each user has its own version of the program, all the local variables in the program are separate between users.

With this approach clicking the Back button in the browser is no longer a hassle to deal with for you as a server-side programmer. They will simply refer to past continuations objects, which have their own state of the local variables.

Since continuations are objects, you can also store them in a database, for really long-lived session, just like you do with session beans.

Errors and Improvements? If you see any errors or potential improvements in this document please help us: View, Edit or comment on the latest development version (registration required).