Forums Register Login

Alternative for cookie in portlet

+Pie Number of slices to send: Send
Hi,

I hope this is in the right area ......, and I hope someone can help with this.

I am writing a portlet. It's a 'quick poll' - the idea is that the page asks the user to vote on a question using a HTML form. Users should only vote once, and given that this is an anonymous site, I originally thought a cookie would be a good way to control this.
IE. Portlet checks to see if cookie exists, if not display question and HTML form. On user submission, store results in the backend DB and set the cookie so that they are not presented with the question/form again.

I've been trying unsuccessfully to use the cookie class and adding it to the HttpServletResponse object with response.addKookie(). (Cookie deliberately spelt with a K to post into this forum)
I've subsequently read that this is not supported in a portlet as the cookie has to be written to the HTTP header before any content, and this cant be guaranteed with a portlet (as the portlet could appear anywhere on the page).
This makes sense, but now I'm stuck as to how to solve the problem.
How do I flag that this PC has already voted ?
I could use client side Javascript to set the cookie (yuck !), but will I be able to read the cookie server side with request.getKookies() ??

Or is there an alternative / better way of doing this ?

Cheers

Nathan
+Pie Number of slices to send: Send
There is no foolproof way to do this. An alternative to consider is to look at the client's IP.

Originally posted by Nathan Russell:
... HttpServletResponse object with response.addKookie(). (Cookie deliberately spelt with a K to post into this forum)



Not that it matters, but curious why you think response.addCookie() cannot be posted to this forum.
+Pie Number of slices to send: Send
 

Originally posted by Sharad Agarwal:

Not that it matters, but curious why you think response.addCookie() cannot be posted to this forum.


Try typing: response.getCookie()
+Pie Number of slices to send: Send
 

There is no foolproof way to do this. An alternative to consider is to look at the client's IP


That wont be foolproof either, as multiple PCs could have the same IP - in the case of an internal network with addresses leased via DCHP (at different times obviously); or the case of an internet site where site visitors are all coming out of one company and one internet connection.

Any other ideas anyone ??
+Pie Number of slices to send: Send
 

Originally posted by Nathan Russell:
That wont be foolproof either, as multiple PCs could have the same IP - in the case of an internal network with addresses leased via DCHP (at different times obviously); or the case of an internet site where site visitors are all coming out of one company and one internet connection.



I didn't say it was , what I did say was: "There is no foolproof way to do this." Cookies are easy enough to delete on the client side, if you were able to get them to work, even they would not be foolproof.

You could take any number of parameters available from the request and use a combination thereof to try to identify an individual user. Cookies that you set, client's IP address are items that come to mind.

Using the cool LiveHTTP headers add-on to firefox that Ben Souther pointed out in a previous post, here is a typical header:


Combine that with what you can get from the network packets (like IP) and choose the combination that works best for your situation.
+Pie Number of slices to send: Send
Did you ever finish the quick polling portlet? I am looking to do the same thing on our site.
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3892 times.
Similar Threads
Websphere Portal - Test 399
Browser Windows(URGENT!)
Cookies on JSP
Difference between portlet and application
Static variables in JS
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:32:07.