title: getting and setting cookie spring mvc
body: <p>I am using <code>@requestbody</code> and <code>@responsebody</code> annotations for my authentication method using Spring MVC. I want to know how can I get and set cookies in spring mvc.. I need to store username and password in my cookie, which I am getting through the <code>requestbody</code>. Also want to know how can I get this set cookie in the browser, the next time the user logs in. Also does the browser sends the cookie automatically with the request body ? To be specific I don't want to go for Spring Security Remember me option. I am new to spring framework so an example code would be highly appreciated. </p>
  
  <p><strong>Ajax Code in JS</strong>: </p>
  
  <pre><code> var ajaxOptions = {
              type: callType,
              url: serviceCompleteUrl,
              /* Add if required.
              dataType: returnType */
              async: false,
              success: function(data, status, xhr) {
                  /*
                   * TODO: See if this is required
                  if (xhr.status == 200) {
                   */
                  ajaxSuccess = true;
                  serviceResponse = data;
                  /*
                  }
                   */
              },
  </code></pre>
  
  <p>in the service I am just returning the object which will be mapped onto the serviceResponse and could be used by JS.. </p>
  
  <p>Sample <strong>code for service</strong> :</p>
  
  <pre><code>  @RequestMapping("/login")
      public @ResponseBody LoginObject Login(@RequestBody LoginParameter request)
      {
         /* Code */
         return LoginObject;
      }
  </code></pre>
  
  <p>This is how I am returning the object from the service, which is then catched by the serviceresponse in js..</p>