Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7442137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:07:48+00:00 2026-05-29T11:07:48+00:00

I have a domain ‘www.foo.com’ and I want to create sub domain ‘test.foo.com’. In

  • 0

I have a domain ‘www.foo.com’ and I want to create sub domain ‘test.foo.com’.
In order to combine those 2 domains to share only one cookie I set the cookie to be like that:

Cookie cookie = new Cookie("myCookie", "myValue");
cookie.setMaxAge(60 * 60);
cookie.setDomain(".foo.com");

So from now on there will be only one cookie: ‘foo.com’ and the values will be save on the same cookie.
The problem is for old users, for them there will be two cookies (‘www.foo.com’ and ‘foo.com’), how can i merge those two cookies to one??

One more thing, users from ‘test.foo.com’ eventually will visit ‘www.foo.com’ and vise versa.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:07:49+00:00Added an answer on May 29, 2026 at 11:07 am

    Get the old cookie from the http servlet request, then set its max age to 0. That will trigger the client side to get rid of it (in its own time, normally right away). Also, see the Javadoc on Cookie.

    setMaxAge

    public void setMaxAge(int expiry) Sets the maximum age in seconds for this Cookie. A positive value indicates that the cookie will expire after that many seconds have passed. Note that the value is the maximum age when the cookie will expire, not the cookie's current age. A negative value means that the cookie is not stored persistently and will be deleted when the Web browser exits. A zero value causes the cookie to be deleted. Parameters: expiry - an integer specifying the maximum age of the cookie in seconds; if negative, means the cookie is not stored; if zero, deletes the cookie See Also: getMaxAge()

    You will need to parse through your cookies and search for the one you are trying to get rid of. Something like this:

    final Cookie[] cookies = request.getCookies();
    for(Cookie cookie: cookies) {
        if("www.foo.com".equals(cookie.getDomain()) cookie.setMaxAge(0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a domain name www.xyz.com and I want to make sure if someone
I have a domain test.com and I want this domain to redirect to mydomain.com/test.
I have a domain set up: www.domain.com, that runs a codeigniter website. I want
For example, I have domain name abc.com I want both abc.com and www.abc.com can
I have a domain and a group of sub-domains that require authentication to access.
I have a domain registered and hosted at hostmonster. I want to create a
I have domain name for eq. 1) http://www.abc.com/search 2) http://go.abc.com/work I get only domain
I have a domain, lets say www.mycompany.com. Is it possible to redirect www.mycompany.com to
I have domain site.com and there is subdomain sub.site.com Once you open sub.site.com you
I have domain www.mysite.com and subdomain api1.mysite.com. There (in domain) are several folders and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.