java - Cookie Not Saving To Another url with the same domain -


this sample code of project. created ajax function on html file go api_base_url/login?id=p1003

$("#trigger").click(function(){  $.ajax({     url : api_base_url + "/login",     type : "get",     data : {id: "p1003"},     success : function (response){         if(response != null) {             window.open(api_base_url + response);                 }             }   }); }) 

in controller there getmapping function "/login" create cookies on domain , return string url on going redirect next.

@requestmapping("/login") public string login(httpservletresponse response, @requestparam(value = "id", defaultvalue = "*") string id){   cookie session_id = new cookie("session_id", id);  session_id.setpath("/");  response.addcookie(session_id);  return "/home"; } 

now have controller "/home" cookies set in browser.

@requestmapping("/home") public modelandview home(httpservletrequest request, httpservletresponse response)         throws ioexception, parseexception {       modelandview mav = new modelandview();      mav.setviewname("home");      cookie[] cookies = request.getcookies();      jsonobject ses = new jsonobject();       system.out.println("cookies " + ses);       return mav;      } 

"/home" controller can't seem find cookies set in "/login" controller though have same domain. whenever go api_base_url/home, cookies empty have visit api_base_url/login?id=p1003 first before api_base_url/home can have cookies needed.

pls stuck t_x


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -