0

can I access cookies added in Javascript in my java servlet??

in my javascript I've done,

var mydata = ace.edit("editor").getValue();
document.cookie="data="+mydata;

how can I access this in my java servlet?

1 Answer 1

2
Cookie[] cookies = request.getCookies();

for (int i = 0; i < cookies.length; i++) {
  String name = cookies[i].getName();
  String value = cookies[i].getValue();
}

try this in servlet.

Sign up to request clarification or add additional context in comments.

4 Comments

But I didnt give any name for the cookie in my js??
check the name of cookie in jquery. It must has some reference.
Your question states that your cookie name is data. You can find it server side by checking for name.equals("data") in above code.
IT says there is no cookie by the name data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.