• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cookie setting

 
Ranch Hand
Posts: 398
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have arequirement that a survey is popped up when a user enters the site first time. If he fills it once we need not pop it up for a year again. And when he is in one session if he minimises or kills it we need not pop it up again if he clicks the home from the website or comes to the website by openiing a new window from the existing browser. I am doing this through javascript. I check for the availability of the cookie and if it is there then don't pop up; else I will pop up the survey. All is well except when the user types in http://ourwebsite.com instead of http://www.ourwebsite.com. The survey pops up if he types in the site name without the www before the website address.


I am setting the cookie like this..



Any idea what I am doing wrong?


Thanks,

Vasu
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add this line of code.
cookie.setDomain(".ourwebsite.com");

~Jay
JavaRSS.com, Java News, Java Articles and Java Blogs, Just one Bookmark.
[ December 15, 2004: Message edited by: Jay King ]
 
vasu maj
Ranch Hand
Posts: 398
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do I have to add two domains? www.ourwebsite.com AND ".ourwebsite.com"? Can one cookie have two domains like that?
 
Jay King
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
.ourwebsite.com will take care of both www.ourwebsite.com and ourwebsite.com.

~Jay
JavaRSS.com, Java News, Java Articles and Java Blogs, Just one Bookmark.
 
vasu maj
Ranch Hand
Posts: 398
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. It was helpful. One thing I wanted to do though is to not hardcode the domain name. Is there a way to get it somehow from request or somewhere and set that to the cookie?

Thanks,

Vasu
 
Jay King
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use methods in HttpServletRequest class.

For example:
host = request.getRemoteHost();
if (host == null)
host = request.getRemoteAddr();

You need to check to see if it starts with www or not. You may have other subdomains like abc.ourwebsite.com. So you need to parse the URL to get the ".ourwebsite.com" and set it in the cookie.

~Jay
JavaRSS.com, Java News, Java Articles and Java Blogs, Just one Bookmark.
 
vasu maj
Ranch Hand
Posts: 398
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Jay,

Here is my problem : getRemoteHost() returns null. getRemoteAddr() returns the ip address ( 233.0.0.1, for example). Is there way to get the host name?

Thanks,

vasu
 
vasu maj
Ranch Hand
Posts: 398
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it from getRequestURL() method.

Thanks,

Vasu
reply
    Bookmark Topic Watch Topic
  • New Topic