iCode
iCode

Reputation: 9202

Java - Getting cookie value without escape characters

I guess this is duplicate. But could not found what I am loking for.

I have one Java Spring MVC web application runniong as server. I have another angularJS application running as client. In AngularJS I am setting some cookies, But the string values are encoded with special characters. It looks like this

id=20; name=%22myname%22

In my Controller I am getting the cookie value id properly, but not name.

Cookie[] cookies=request.getCookies();

String name=cookies[1].getValue();
System.out.println(name);

And it prints

%22myname%22

How to get rid of this encoded characters?

Upvotes: 0

Views: 4972

Answers (2)

Mustafa Genç
Mustafa Genç

Reputation: 2579

You can decode your string in your controller as follows:

URLDecoder.decode(name, "utf8")

Upvotes: 2

Shyam
Shyam

Reputation: 6444

String value = URLDecode.decode(cookie.getValue(), "UTF-8");

Upvotes: 1

Related Questions