2

I am trying to retrieve a cookie from a spring controller to a javascript code of a jsp page. This is the controller code

@CookieValue(required = true) String data) {
System.out.println("this is the sound cookie value>>>>>> " + data); //this prints the xyz cookie value to the console

Now in my javascript of a jsp page I am trying to retrieve the cookie this way

var cokdata= "${cookie['data']}";
        console.log("value>>>>>>> "+cokdata); //it returns nothing

Please how can I retrieve the cookie value in a javascript code of a jsp page

  • I don't know this annotation, but this is probably the problem, the EL is correct (add the full code please of this method) – AxelH Oct 20 '16 at 11:22
  • http://stackoverflow.com/questions/10730362/get-cookie-by-name – Senthil Oct 20 '16 at 11:24
  • @Senthilnathan Look at this one ... http://stackoverflow.com/questions/19116040/getting-cookie-in-jsp the get is correct ! – AxelH Oct 20 '16 at 11:26

1 Answers1

0

If you are open to using jQuery, you could use $.cookie('data') to retrieve the cookie as described here.

Note that cookies are just another header with name Cookie and values will be your key:pair cookie contents. For example in this case the cookie header be Cookie:data=data_contents,cookie2:cookie2_contents,cookie3:cookie3_contents

Community
  • 1
  • 1
Michael
  • 134
  • 1
  • 5