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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:04:55+00:00 2026-06-14T05:04:55+00:00

Lets say I have a Spring MVC form like this: <form:form action=${pageContext.servletContext.contextPath}/secure/main.htm commandName=secure/main> <form:input

  • 0

Lets say I have a Spring MVC form like this:

<form:form action="${pageContext.servletContext.contextPath}/secure/main.htm" commandName="secure/main">

    <form:input path="operatorId" cssClass="textField"/>

    <form:input path="clientId" cssClass="textField"/>

</form:form>

What I am trying to do is to store those fields values in the cookies that they will be saved other time user logins into the system. It is similar to Remember Me checkbox, but just without the checkbox. My controller looks like this:

@RequestMapping(method = RequestMethod.POST)
public String processAuthenticate(@Valid AuthenticationForm authenticationForm,
                                  Map<String, Object> model,
                                  HttpServletRequest request,
                                  HttpServletResponse response) {

    authenticationForm = (AuthenticationForm) model.get("authenticationForm");

    Cookie[] cookies = request.getCookies();
    for (Cookie cookie : cookies) {
        System.out.println(cookie.getValue());
        if (cookie.getName().equals("clientId")) {
            authenticationForm.setClientId(cookie.getValue());
        } else if (cookie.getName().equals("operatorId")) {
            authenticationForm.setOperatorId(cookie.getValue());
        }
    }

    String clientId = authenticationForm.getClientId();
    String operatorId = authenticationForm.getOperatorId();

    Cookie cookieClientId= new Cookie("clientId", clientId);
    cookieClientId.setMaxAge(COOKIE_EXPIRY);
    response.addCookie(cookieClientId);

    Cookie cookieOperatorId = new Cookie("operatorId", operatorId);
    cookieOperatorId.setMaxAge(COOKIE_EXPIRY);
    response.addCookie(cookieOperatorId);

    return MAIN_FORM_MAPPING;
}

But when I click the button and this method is invoked, my values are not saved. It is the first time I am trying to use Cookies so maybe I am missing something? I was following this SO question. But in my case this does not work. Anybody could advice me with the solution to this problem?

  • 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-06-14T05:04:57+00:00Added an answer on June 14, 2026 at 5:04 am

    Sorry for the false alarm. I was doing everything right, but I had a method which within each request returned new AuthenticationForm object as a model attribute, like this:

    @ModelAttribute("secure/" + MAIN_FORM_MAPPING)
    public AuthenticationForm getAuthenticationForm() {
        return new AuthenticationForm();
    }
    

    And I had a method which is used to show the form in the view:

    @RequestMapping(method = {RequestMethod.GET})
    public String showForm(Map<String, Object> model, HttpServletRequest request) {
        AuthenticationForm authenticationForm = (AuthenticationForm) model.get("secure/main");
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            System.out.println(cookie.getValue());
            if (cookie.getName().equals("clientId")) {
               authenticationForm.setClientId(cookie.getValue());   //Just added this code to this method
            } else if (cookie.getName().equals("operatorId")) {
               authenticationForm.setOperatorId(cookie.getValue());
            }
        }
        return MAIN_FORM_MAPPING;
    }
    

    Then I realized that this form object is always new, so the values I am setting from cookies always on a new form. I had to set the values from cookies in the showForm method and everything is working.

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

Sidebar

Related Questions

Lets say a have a string such as this one: string txt = Lore
So lets say I have an string like so. $pizza = 1,2,3,5-4,7; and what
Lets say I have this code: public void MyMethod(string Data, List<string> InputData) { //I
Lets say I have this class in foobar-shared.lib: class FooBar { std::string m_helloWorld; }
Let's say I have a Spring MVC web application and it allows users to
So, let's say I have this code (VB.Net): Sub Main() dim xxx as string
Let's say I have settings classes in my controllers and models, in my Java/Spring/MVC
Let's say I have a handler in a Spring MVC controller: @RequestMapping public String
I am using Hibernate with my Spring MVC project. Lets say my model has
Lets say I have the string: MyNamespace.SubNameSpace.MyClassName How do I extract just everything after

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.