O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Kim wants to keep client-specific state across multiple requests

image with no caption

Right now, the business logic in the model simply checks the parameter from the request and gives back a response (the advice). Nobody in the app remembers anything that went on with this client prior to the current request.

What he has NOW:

image with no caption

What he WANTS:

public class BeerExpert {

   public NextResponse getAdvice(String answer) {
      // Process client answer by looking at
      // ALL of the client's previous answers, as well
      // as the answer from the current request.
      // if there's enough info, return final advice,
      // else, return the next question to ask
   }
}

Note

The model (the business logic) has to figure out whether it has enough information to make a recommendation (in other words, to give final advice), and if it doesn’t, it has to give back the next question to ask the user.

Note

Assume the NextResponse class encapsulates the next thing to display for the user, and something that indicates whether it’s the final advice recommendation or another question.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required