0

Use of cookies

asked 2010-02-05 03:33:32 +0800

din gravatar image din
251 1 5

I want to show different homepages to differetn groups of user. How can I achieve that?
As a guest user I want to see different screen but as admin I want to see different. How can I do that? Can cokkies be used or is there any way I can do that?

delete flag offensive retag edit

9 Replies

Sort by » oldest newest

answered 2010-02-05 05:54:01 +0800

mjablonski gravatar image mjablonski
1284 3 5
http://www.jease.org/

If you want to use Cookies, you can use little helpers as the following:

	public static void setCookie(String name, String value) {
		((HttpServletResponse) Executions.getCurrent().getNativeResponse()).addCookie(new Cookie(
				name, value));
	}

	public static String getCookie(String name) {
		Cookie[] cookies = ((HttpServletRequest) Executions.getCurrent().getNativeRequest())
				.getCookies();
		if (cookies != null) {
			for (Cookie cookie : cookies) {
				if (cookie.getName().equals(name)) {
					return cookie.getValue();
				}
			}
		}
		return null;
	}

HTH, Maik

link publish delete flag offensive edit

answered 2010-02-06 10:19:21 +0800

din gravatar image din
251 1 5

Thanks for the help!!!also want to know how should I apply this code??? How can I invoke the call to the cookie and set the cookie??

link publish delete flag offensive edit

answered 2010-02-07 19:29:30 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

updated 2010-02-07 19:40:05 +0800

They just static method, you can put them in a class such as "CookieUtil.java"

You can use composer, and set the cookie value when user login
getCookie in doAfterCompose method and to decision what is user's view, like this

if ( CookieUtil.getCookie( userBean.getName() ) == "A") {
    mainPanel.appendChild(Executions.createComponents("A.zul", null, null));
} else {
    mainPanel.appendChild(Executions.createComponents("B.zul", null, null));
}

link publish delete flag offensive edit

answered 2010-02-08 02:46:00 +0800

din gravatar image din
251 1 5

Great...thanks very much for all your help.
I will try and get back if I need help further.

Dino

link publish delete flag offensive edit

answered 2010-08-13 01:28:13 +0800

din gravatar image din
251 1 5

I need another help.

The problem I am facing is, the cookie is becoming the browser’s instance specific.

For example, if I open a browser and hit the application the cookie get set and on refreshing the same window the expected behaviour comes but if I close the browser window and open another browser window and hit the application I find that cookie value is lost.

Please let me know if I am using the cookie APIs correctly within the framework or if I need to use it some other way.

link publish delete flag offensive edit

answered 2010-08-13 02:09:39 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

updated 2010-08-13 02:09:51 +0800

Have you set the age of cookie?

link publish delete flag offensive edit

answered 2010-08-13 03:47:14 +0800

din gravatar image din
251 1 5

You are right, I forgot to do that, now I am fine with the output.
Thanks,
Dino

link publish delete flag offensive edit

answered 2011-08-11 01:40:17 +0800

wangfei6 gravatar image wangfei6
3

i want to set cookies from action in strust2,how can i get cookies from zk?

link publish delete flag offensive edit

answered 2011-08-11 05:51:11 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

if you were correctly set the cookie in any response, than you could get cookies by HttpServletRequest.getCookies , and you can get the request by Exectuions.getCurrent().getNativeRequest()/

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2010-02-05 03:33:32 +0800

Seen: 2,528 times

Last updated: Aug 11 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More