|
Expresso 5-6 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
A PersistentSession is simply a place to stash some values between states of a controller object. Different environments may employ different ways of doing this - the simplest being SimplePersistentSession, where a hashtable does all the required work.
The typical way to use a PersistentSession is within a controller object as part of your state handler. You do not instantiate it directly, the controller framework instantiates the appropriate kind of session for you. [Unless you're directly creating a controller yourself, such as in a command line environment, in which case, you would set the session object at say, SimplePersistentSession... if you're getting confused at what is meant by this, ignore it.]
Example Usage:
void protected runMyState(ControllerRequest request, ControllerResponse response) throws ControllerException {
PersistentSesssion session = request.getSession();
//Set an attribute that exists only for the current request.
session.setAttribute("RequestAttribute", "Controller Was Executed");
//Set an attribute that exists for the entire session
session.setPersistentAttribute("SessionAttribute","Customer Has Logged In");
//Set an attribute that persists across requests. [In HTTP sets a cookie]
session.setClientAttribute("ACookie", "Cookie Data That May Get Encrypted");
| Method Summary | |
Object |
getAttribute(String attribName)
Retrieves the object from the request context. |
Enumeration |
getAttributeNames()
Retrieves all attribute names in the request context. |
String |
getClientAttribute(String attribName)
Retrieves a value of a cookie set on the client's system. |
Enumeration |
getPeristentAttributeNames()
Retrieves all attribute names from the session context. |
Object |
getPersistentAttribute(String attribName)
Retrieves the object from the session context. |
void |
invalidate()
Clear out the session. |
void |
removeAttribute(String attribName)
Clears an attribute from the request context |
void |
removePersistentAttribute(String attribName)
Clears an attribute from the session context |
void |
setAttribute(String attribName,
Object attribValue)
Sets an attribute that is valid for the duration of the request. |
void |
setClientAttribute(String attribName,
String attribValue)
If in HTTP environment, it sets an encrypted cookie to the client. |
void |
setPersistentAttribute(String attribName,
Object attribValue)
Saves an attribute to the actual session, rather than simply the response. |
| Method Detail |
public void setAttribute(String attribName,
Object attribValue)
attribName - The name of the object you wish to set.attribValue - the object you want to set.public Object getAttribute(String attribName)
attribName - the name of the object to retrieve
public Enumeration getAttributeNames()
public void setClientAttribute(String attribName,
String attribValue)
attribName - the name of the attribute toattribValue - the value of the attribute to set.public String getClientAttribute(String attribName)
expresso-config.xml
file.
attribName - the name of the cookie to retrieve
public Enumeration getPeristentAttributeNames()
public void setPersistentAttribute(String attribName,
Object attribValue)
attribName - the name of the attribute to setattribValue - a Serializable java object.Serializablepublic Object getPersistentAttribute(String attribName)
attribName - the name of the object to retrieve
public void invalidate()
public void removeAttribute(String attribName)
attribName - the name of the attribute to remove.public void removePersistentAttribute(String attribName)
attribName - the name of the attribute to remove.
|
Expresso 5-6 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||