ZATS Cookies"

From Documentation
Line 3: Line 3:
 
  Since 1.1.0
 
  Since 1.1.0
  
== Cookies handling ==
+
 
 
In order to provide developers handle the [http://www.ietf.org/rfc/rfc2965.txt HTTP cookies], ZATS Mimic introduces a group of methods on  
 
In order to provide developers handle the [http://www.ietf.org/rfc/rfc2965.txt HTTP cookies], ZATS Mimic introduces a group of methods on  
  
 +
'''cookie.zul'''
 +
<source lang="java" start="10" high="15,18,19,29">
 +
<zscript><![CDATA[
 +
public void setCookie(String name, String value) {
 +
javax.servlet.http.HttpServletResponse resp = Executions.getCurrent().getNativeResponse();
 +
resp.addCookie(new javax.servlet.http.Cookie(name, value));
 +
}
 +
setCookie("foo", "bar");
 +
]]>
 +
</zscript>
 +
<button id="change" label="change" onClick='setCookie("foo", "hello");' />
 +
<button id="show" label="show">
 +
<attribute name="onClick"><![CDATA[
 +
javax.servlet.http.HttpServletRequest req = Executions.getCurrent().getNativeRequest();
 +
StringBuilder sb = new StringBuilder();
 +
for (javax.servlet.http.Cookie c : req.getCookies())
 +
sb.append(c.getName()).append("=").append(c.getValue()).append(";");
 +
msg.setValue(sb.toString());
 +
]]>
 +
</attribute>
 +
</button>
 +
<label id="msg" />
 +
</source>
 +
 +
* '''Line 15''': This will add a cookie when beginning.
 +
*
 +
 +
'''Test.java'''
 +
<source lang="java" start="10" high="">
 +
Zats.init(".");
 +
try{
 +
Client client = Zats.newClient();
 +
DesktopAgent desktop = client.connect("/~./basic/cookie2.zul");
 +
Assert.assertEquals("bar", client.getCookie("foo"));
 +
Assert.assertEquals(null, client.getCookie("not existed"));
 +
desktop.query("#change").click();
 +
Assert.assertEquals("hello", client.getCookie("foo"));
 +
}finally{
 +
Zats.end();
 +
}
 +
</source>
 +
 +
* '''LIne 11''': dfa.
 +
 +
== Cookie handling from client-side ==
 +
 +
<source lang="java" start="10" high="">
 +
 +
</source>
 +
 +
== Cookies handling ==
  
 
{{ZATSEssentialsPageFooter}}
 
{{ZATSEssentialsPageFooter}}

Revision as of 13:10, 8 June 2012

WarningTriangle-32x32.png This page is under construction, so we cannot guarantee the accuracy of the content!

aowang



Since 1.1.0


In order to provide developers handle the HTTP cookies, ZATS Mimic introduces a group of methods on

cookie.zul

<zscript><![CDATA[
	public void setCookie(String name, String value) {
		javax.servlet.http.HttpServletResponse resp = Executions.getCurrent().getNativeResponse();
		resp.addCookie(new javax.servlet.http.Cookie(name, value));
	}
	setCookie("foo", "bar");
]]>
</zscript>
<button id="change" label="change" onClick='setCookie("foo", "hello");' />
<button id="show" label="show">
	<attribute name="onClick"><![CDATA[
		javax.servlet.http.HttpServletRequest req = Executions.getCurrent().getNativeRequest();
		StringBuilder sb = new StringBuilder();
		for (javax.servlet.http.Cookie c : req.getCookies())
			sb.append(c.getName()).append("=").append(c.getValue()).append(";");
		msg.setValue(sb.toString());
	]]>
	</attribute>
</button>
<label id="msg" />
  • Line 15: This will add a cookie when beginning.

Test.java

Zats.init(".");
try{
	Client client = Zats.newClient();
	DesktopAgent desktop = client.connect("/~./basic/cookie2.zul");
	Assert.assertEquals("bar", client.getCookie("foo"));
	Assert.assertEquals(null, client.getCookie("not existed"));
	desktop.query("#change").click();
	Assert.assertEquals("hello", client.getCookie("foo"));
}finally{
	Zats.end();
}
  • LIne 11: dfa.

Cookie handling from client-side

Cookies handling


Last Update : 2012/06/08

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