Wednesday, September 23, 2009

Creating Cookie in a Session

The ViewCommandContext offers the getResponse() method which can be used to gain access to the HttpServletResponse, from where you can add the cookies.

http://publib.boulder.ibm.com/infocenter/wchelp/v6r0m0/index.jsp?topic=/com.ibm.commerce.api.doc/com/ibm/commerce/command/ViewCommandContext.html

For example:

if ( commandContext instanceof com.ibm.commerce.command.ViewCommandContext ) {
 com.ibm.commerce.command.ViewCommandContext v = (com.ibm.commerce.command.ViewCommandContext)commandContext;
 javax.servlet.http.HttpServletResponse response = (javax.servlet.http.HttpServletResponse)v.getResponse();
 javax.servlet.http.Cookie myCookie = new javax.servlet.http.Cookie("name","value");
 response.addCookie(myCookie);
} 

No comments:

Post a Comment