Use cookies"
From Documentation
Maya001122 (talk | contribs) m (Created page with '{{ZKDevelopersGuidePageHeader}} For a Web application, [http://en.wikipedia.org/wiki/HTTP_cookie <tt>cookies</tt>] are used for maintaining specific information about users at c…') |
Robertwenzel (talk | contribs) m |
||
Line 1: | Line 1: | ||
{{ZKDevelopersGuidePageHeader}} | {{ZKDevelopersGuidePageHeader}} | ||
+ | |||
+ | {{Old Version | ||
+ | |url=https://www.zkoss.org/wiki/ZK_Developer%27s_Reference/UI_Patterns/Communication/Inter-Application_Communication#Use_Cookie | ||
+ | |}} | ||
+ | |||
For a Web application, [http://en.wikipedia.org/wiki/HTTP_cookie <tt>cookies</tt>] are used for maintaining specific information about users at client browser side. In the following example, when you click the <tt>button</tt>, a cookie named "user" will be set and get. | For a Web application, [http://en.wikipedia.org/wiki/HTTP_cookie <tt>cookies</tt>] are used for maintaining specific information about users at client browser side. In the following example, when you click the <tt>button</tt>, a cookie named "user" will be set and get. |
Revision as of 02:53, 25 July 2017
This documentation is for an older version of ZK. For the latest one, please click here.
This documentation is for an older version of ZK. For the latest one, 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()"/>
</window>
And MyWindow.java,
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");
response.addCookie(userCookie);
//get cookie
Cookie [] cookies = ((HttpServletRequest)Executions.getCurrent().getNativeRequest()).getCookies();
System.out.println(cookies[0].getName());
} catch (Exception e) {
e.printStackTrace();
}
}
}