Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Alternative for cookie in portlet

 
Nathan Russell
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sharad Agarwal
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()
 
Nathan Russell
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ??
 
Sharad Agarwal
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nathaniel Beck
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you ever finish the quick polling portlet? I am looking to do the same thing on our site.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic