From Documentation

Jump to: navigation, search

Stop.png This documentation is for an older version of ZK. For the latest documentation please click here.

For a Web application, cookies are used for maintaining specific information about users at client browser side. In the following example, when you click the button, a cookie named "user" will be set and get.

<window use="MyWindow">
	<button label="cookie" forward="onCookie()"/>


import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.zkoss.zk.ui.Executions;
import org.zkoss.zul.Window;
public class MyWindow extends Window {	
	public void onCookie(){
		try {
			//add cookie
			HttpServletResponse response = (HttpServletResponse)Executions.getCurrent().getNativeResponse();
			Cookie userCookie = new Cookie("user", "xxx123");
			//get cookie
			Cookie [] cookies = ((HttpServletRequest)Executions.getCurrent().getNativeRequest()).getCookies();
		} catch (Exception e) {

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.