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 6545181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:33:18+00:00 2026-05-25T11:33:18+00:00

I am having a problem of setting the data of a (persistent/cross browser session)

  • 0

I am having a problem of setting the data of a (persistent/cross browser session) cookie correctly inside a Servlet and the reading it in a Filter.

the code of the Servlet (running at log-in time) is:

    String encodedValue = new String(Base64
        .encodeBase64(req.getParameter("account").getBytes()));
    Cookie cookie = new Cookie("projectAuthenticationCookie", encodedValue );
    cookie.setMaxAge(24*60*60);
    cookie.setPath("/");
    res.addCookie(cookie);

This will get the cookie inside the response, but the when I read it within my filter with the following code:

    Cookie authenticationCookie = null;
    Cookie[] cookies = ((HttpServletRequest) request).getCookies();
    for (Cookie cookie : cookies){
        if ("projectAuthenticationCookie".equals(cookie.getName())) {
            authenticationCookie = cookie;
        }
    }

I only get the value I set right, all other fields are either null, empty or different. Max age for example always returns -1 and thus the cookie will never persist.

cookie return values

I tried setting the expires-header with:

    res.setDateHeader("Expires", System.currentTimeMillis() + 24*60*60*1000);

as I read that without a valid expires-header the session will timeout anyway (correct me if I am wrong), but that didn’t help either…

One issue I am thinking of is that I am running on localhost (tried setting cookie.setDomain(“localhost”) but also no luck). My web server/serclet container is Jetty 7 but I do not think that this is relevant…

Any hints?

  • 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-25T11:33:19+00:00Added an answer on May 25, 2026 at 11:33 am

    The fields other than name and value are not populated (and thus not meaningful) on cookies you get from a request.

    These fields are intended to inform the browser about the max age; path, etc. of the cookie, but the browser doesn’t send back this information to the server. The only time where it’s important to have the correct max age, path, etc. is when you create a cookie and add it to the response. Use your browser to check if it stores the correct information instead of trying to find it at server-side.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem setting a cookie and doing a 302 redirect In chrome
I am having a problem where a cookie I am setting is being lost
I seem to be having a problem setting the values of an array inside
I am having a problem setting the Authorize attribute Role value from a variable.
I am having a problem setting up the following in Visual Studio 2008: a
I am having a problem setting the background of UITableView to a UIImageView (see
I am in the process of setting up CruiseControl.NET. The problem I am having
I'm using a ViewPager in my project, and having a little problem at setting
I am having some problem with my UITableView. I am downloading the data and
I am having problems setting the educationflag variable to 1. The problem I am

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.