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.

Get Head First Servlets and JSP, 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.