8.6 MANAGING SESSIONS

We have been looking at JSP and servlets for handling and generating HTTP streams. In the previous section, we identified a design pattern called MVC that enables a unified approach to browser applications, which allows us to handle requests, call business logic, and then hand off to the appropriate JSP to generate the output stream (the user interface).

What we omitted from the previous discussion was any detail about how to support state in our application, which is known as session management. This problem is easiest to identify by example.

Figure 8.41 illustrates the problem well. Here we have a sequence of page requests within our example billing application. Each page is requested by the user, initially by entering the application's homepage and then drilling down (and back up) the application by successive link selection. As we have been discussing, the billing application is most likely handled by one servlet or JSP on the server (ignore the issues relating to MVC patterns for now). For the sake of defining a session, we herein identify that a session is the traversal in time from the start of the application through to the end, either by logging out (or leaving) or timing out. This is shown as the journey from A to B in the figure.

It may seem an odd reflection, but how do we know where we are in the application? Or, more accurately, how does the servlet know whereabouts we are in the application in order to invoke the correct business logic and redirection ...

Get Next Generation Wireless Applications: Creating Mobile Applications in a Web 2.0 and Mobile 2.0 World, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.