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…') |
m (correct highlight (via JWB)) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
{{ZKDevelopersGuidePageHeader}} | {{ZKDevelopersGuidePageHeader}} | ||
− | For a Web application, [http://en.wikipedia.org/wiki/HTTP_cookie < | + | {{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 <code>cookies</code>] are used for maintaining specific information about users at client browser side. In the following example, when you click the <code>button</code>, a cookie named "user" will be set and get. | ||
<source lang="xml" > | <source lang="xml" > |
Latest revision as of 10:40, 19 January 2022
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();
}
}
}