Work in progress!

Client Techniques

Server Techniques

Client + Server Techniques

Cookies

URLs

HTML form hidden fields

Browser Objects

Session

Database

Hidden fields + session

Hidden fields + database

Query parameters

Clean URLs

Advantages

Can store complex data types

+

+

Works well in load balancing environments

+

+

+

+

+

Works well in Ajax applications

+

+

+

Disadvantages

User can tamper with state information

+

+

+

Requires cookies

+

+

Requires coding

+

+

+

Requires redirection

+

Requires Javascript

+

+

Can store only small amount of data (~2,000 bytes)

+

+

Increased network traffic and slightly slower response times

+

+

+

+

Requires server resources to save state information

+

Application logic tightly coupled to the user interface implementation

+

Does not work well with redirection

+

+

State can be lost on page reload

+

State can be lost on direct navigation

+

+

+

State can be lost when client is idle

+

Neither Advantages Or Disadvantages

State is not tied to view

+

+

+

Client-Side Techniques

Cookies

Pro:

Neither:

Cons:

Best fit: non-critical information about a particular client, session, or application. Usually employed for user profiling, like zip code or preferred language. Also used for "remember me" login.

How Struts can help:

Rewritten URLs

Query parameters

URL query parameters allow to express a website structure using base path to a resource, in case of Struts that would be an action, and series of query parameters

For example, an online tire store may expose its structure like this:

    www.tirestore.com/vehicle.do?year=2002&make=TOYOTA&model=mr2spyder

A series of HTML forms may help a user to get to desired location, making the address more detailed from step to step:

Welcome page allows to select search criteria:
    www.tirestore.com/welcome.do

We choose to search product by vehicle year and make:
    www.tirestore.com/vehicle.do?year=2002&make=TOYOTA

Then application shows a listbox with applicable model names and allows to select one:
    www.tirestore.com/vehicle.do?year=2002&make=TOYOTA&model=mr2spyder

Pro:

Cons:

Neither:

Best fit: applications where the query string only affects the view, like online catalogs or magazines. A page can be reloaded without affecting the server and without POSTDATA messages. Navigating back and forward is not an issue.

Clean URLs

Clean URLs or cool URLs is a way to express website structure using location path instead of query parameters. Clean URLs work best for static websites. Representing state with clean URLs is less common. It is not convenient either, especially when location is being built as a result of an HTML form submission.

For example, an online tire store may expose its structure like this:

www.tirestore.com/vehicle/2002/toyota/mr2spyder/

A series of HTML forms may help a user to get to desired location, making the address more detailed from step to step:

Welcome page allows to select search criteria:
    www.tirestore.com/welcome

We choose to search product by vehicle year and make:
    www.tirestore.com/vehicle/2002/toyota/

Then application shows a listbox with applicable model names and allows to select one:
    www.tirestore.com/vehicle/2002/toyota/mr2spyder/

Pros:

Cons:

Neither:

Best fit: online catalogs or magazines that have hierarchical structure and should be represented as a static website. May improve site searchability and page rankings.

Additional information:

Browser objects (DOM elements, Javascript variables, Flash storage)

Pro:

Neither:

Cons:

Best fit: Ajax-style Single Page applications.

How Struts can help:

Additional information:

HTML form hidden fields

By year, vehicle, make:

<form action="...">
  <input type="hidden" name="yr" value="2002"/>
  <input type="hidden" name="mk" value="TOYOTA"/>
  <input type="hidden" name="model" value="mrspyder"/>
  ...
</form>  

Pros:

Neither:

Cons:

When to use: all application pages are based on HTML forms and storing state information in the URL is undesireble.

What to store: non-critical state information, like state of controls and widgets (viewstate).

What to keep in mind: the moment you update the server objects or database, you switch from pure client-based technique to combined client-server tecnhique, which is a totally different beast. Many developers using hidden fields think they use client-based state tracking technique while in fact they are not.

Implications: Application must provide explicit navigational links and buttons so users would not have to use standard browser navigation buttons. Application must recognize and handle double-submit situations.

How Struts can help:

Server-Side Techniques

Server session object

Server session object only

Pro:

Neither:

Cons:

Best fit: Ajax- and non-Ajax applications that treat server state as primary, and client state is secondary. If discrepancy between view and model occurs, view is synched with the model, not vice versa.

Server session object + redirection after submitting an HTML form

Pro:

Cons:

Best fit: applications that treat server state as primary state source. Non-Ajax Single Page Applications.

How Struts can help:

Combination Client-Server Techniques

HTML form hidden fields + database

This is one of the more popular state management techniques. It is often used in situations where storing complete state information on server is undesired for performance reasons. Hidden fields store intermediate state during, for example, filling out a series of forms like wizard pages. One of the classic examples is web store checkout process. A series of screens ask for name, address, payment information, delivery optins, etc. The last page in the series submits the shopping cart to the server, where it is processed, the inventory is adjusted and user's credit card is charged.

Two different states have been created: client state and server state. At this point these states are synchronized, but what happens if a user clicks Back or Reload button? A Reload button will cause resubmit of the same request, which will cause server code to charge a user's credit card and to adjust warehouse inventory one more time.

Clicking Back button will cause browser to display checkout page with the cart, this page does not represent server state anymore, here you can see that server state and client state got out of sync. Synchonizing server to client is not possible, database update has been committed and cannot be rolled back. What is left is either synchronizing view to server (preferred choice), or throwing exception and bailing out to some safe location like welcome page.

Pros:

Cons:

When to use: all application pages are based on HTML forms and storing state information in the URL is undesireble.

What to store: non-critical state information, like state of controls and widgets (viewstate).

Implications: With this technique state information is saved on server from time to time (checkpoints). Thus, synchronization between client and server state will be required. Moving back in browser session history should either be prohibited after a "save-to-server" checkpoint, or application must be able to synchronize client and server state. Application must recognize and handle double-submit situations. Application must provide explicit navigational links and buttons so users would not have to use standard browser navigation buttons.

How Struts can help:

todo, saved for later

StateManagement (last edited 2009-09-20 23:12:30 by localhost)