-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I am trying to send some headers when redirecting. Sample code is:
*Executions.getCurrent().setResponseHeader("auth", "abcd");
Executions.getCurrent().sendRedirect(Url,"_");*
But on the redirected URL (servlet) I am not able to retrieve "auth". Have also tried:
*Executions.getCurrent().setAttribute("auth", "abcd");
Executions.getCurrent().addResponseHeader("auth", "abcd");*
But still not able to get hold of auth. Could you please suggest some mechanism for the same?
You can use cookie or put it in session,
e.g.,
test.zul
<zk>
<button label="test">
<attribute name="onClick"><![CDATA[
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
// use cookie
Cookie userCookie = new Cookie("auth", "abcd");
((HttpServletResponse)Executions.getCurrent().getNativeResponse()).addCookie(userCookie);
// put it in session
Sessions.getCurrent().setAttribute("auth", "abcd");
Executions.sendRedirect("test2.zul");
]]></attribute>
</button>
</zk>
test2.zul
<zk>
<textbox rows="5" width="350px">
<attribute name="onCreate"><![CDATA[
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Cookie;
String value = "In Cookies - \n";
Cookie[] cookies = ((HttpServletRequest)Executions.getCurrent().getNativeRequest()).getCookies();
for (Cookie c : cookies) {
value += c.getName() + ": " + c.getValue() + "\n";
}
self.setValue(value);
]]></attribute>
</textbox>
<div />
<textbox rows="5" width="350px">
<attribute name="onCreate"><![CDATA[
self.setValue("From Session - auth: " + Sessions.getCurrent().getAttribute("auth"));
]]></attribute>
</textbox>
</zk>
By the way, sendRedirect in ZK is not a real redirect with response code 302 (i.e., you will not see a response with status 302 in browser console) since ZK is an ajax framework and there are lots of limitation of 302-redirect within an ajax call.
Asked: 2013-05-01 07:42:08 +0800
Seen: 38 times
Last updated: Jun 20 '13
Do not update to ZK Studio 2.0
Catch Server 503 Error - Or Catch Stale Page
how to save spreadsheet data into postgres database?
One controller file with multiple zul file
Why am I getting authentication error for ZK studio activation?
How can i make Tomcat (with virtual hosts) to parse the zul page in subfolders?