ch7.cookie
Class ControllerHelper

java.lang.Object
  extended by shared.HelperBaseCh4
      extended by shared.HelperBaseCh5
          extended by shared.HelperBaseCh6
              extended by ch7.cookie.ControllerHelper

public class ControllerHelper
extends HelperBaseCh6

Read, write, delete and find cookies.


Nested Class Summary
 
Nested classes/interfaces inherited from class shared.HelperBaseCh4
HelperBaseCh4.SessionData
 
Field Summary
 
Fields inherited from class shared.HelperBaseCh6
checked, selected
 
Fields inherited from class shared.HelperBaseCh4
logger, request, response
 
Constructor Summary
ControllerHelper(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Call the base class constructor to store the request and response.
 
Method Summary
 void copyFromSession(java.lang.Object sessionHelper)
          Noting to do, but it still needs to be defined, since the super class is abstract and this is the abstract method.
 java.lang.String deleteMethod()
          The method to call when the deleteCookie button is clicked.
protected  void doGet()
          There is no bean for this application, only cookies.
 java.lang.String findMethod()
          The method to call when the findCookie button is clicked.
protected  java.lang.String jspLocation(java.lang.String page)
          Encapsulates the location of the JSPs.
 java.lang.String setMethod()
          The method to call when the setCookie button is clicked.
 java.lang.String setSpecificMethod()
          The method to call when the processCart button is clicked.
 java.lang.String showMethod()
          The method to call when the showCookie button is clicked.
 
Methods inherited from class shared.HelperBaseCh6
addChecked, addChoice, addSelected, clearMaps, clearProperty, getChecked, getSelected, invokeGetter, setCheckedAndSelected, setCheckedAndSelected
 
Methods inherited from class shared.HelperBaseCh5
getErrors, isValid, isValidProperty, setErrors
 
Methods inherited from class shared.HelperBaseCh4
addHelperToSession, addHelperToSession, doPost, executeButtonMethod, executeButtonMethod, fillBeanFromRequest, invokeButtonMethod, writeError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ControllerHelper

public ControllerHelper(javax.servlet.http.HttpServletRequest request,
                        javax.servlet.http.HttpServletResponse response)
Call the base class constructor to store the request and response.

Parameters:
request - Request information encapsulated in a Java object
response - Response information encapsulated in a Java object
Method Detail

copyFromSession

public void copyFromSession(java.lang.Object sessionHelper)
Noting to do, but it still needs to be defined, since the super class is abstract and this is the abstract method.

Specified by:
copyFromSession in class HelperBaseCh4
Parameters:
sessionHelper - The old helper that is still in the session.

jspLocation

protected java.lang.String jspLocation(java.lang.String page)
Encapsulates the location of the JSPs.

Parameters:
page - The file name of the JSP.
Returns:
The full path to the JSP.

showMethod

public java.lang.String showMethod()
The method to call when the showCookie button is clicked.

Forward to the ShowCookies page.

The method is adorned with a ButtonMethod annotation that associates the name of a button with the method.

Returns:
The address for the JSP.

setMethod

public java.lang.String setMethod()
The method to call when the setCookie button is clicked.

Create two cookies and add them to the response. The cookies can be retrieved from any path on the server. One of the cookies will last until the browser closes, the other will expire in 15 seconds.

The method is adorned with a ButtonMethod annotation that associates the name of a button with the method.

Returns:
The address for the JSP.

deleteMethod

public java.lang.String deleteMethod()
The method to call when the deleteCookie button is clicked.

Delete the cookie by creating an identical cookie and setting its age to zero. The path must match the path of the existing cookie.

The method is adorned with a ButtonMethod annotation that associates the name of a button with the method.

Returns:
The address for the JSP.

findMethod

public java.lang.String findMethod()
The method to call when the findCookie button is clicked.

Retrieve all the cookies from the request and loop through them, looking for a cookie that has the matching name. Set a request attribute based on whether the cookie was found.

The method is adorned with a ButtonMethod annotation that associates the name of a button with the method.

Returns:
The address for the JSP.

setSpecificMethod

public java.lang.String setSpecificMethod()
The method to call when the processCart button is clicked.

Loops through all the items in the cart and calculates the total number of items and the total price.

The method is adorned with a ButtonMethod annotation that associates the name of a button with the method.

Returns:
The address for the JSP.

doGet

protected void doGet()
              throws javax.servlet.ServletException,
                     java.io.IOException
There is no bean for this application, only cookies. The controller only executes the button method and forwards the request and response to the next address.

Overrides:
doGet in class HelperBaseCh4
Throws:
javax.servlet.ServletException
java.io.IOException