spring - How to Decode Unicode Characters from Cookie -
i saving list in string format encoding utf-8. see {
, }
, :
... , more symbols in cookie value.
%7b%22evt%22%3a%5b%5d%2c%22exc%22%3a%5b%5d%2c%22tourquantity%22%3a%221%22%2c%22tourid%22%3a%22067e61623b6f4ae2a1712470b63dff00%22%2c%22room%22%3a%7b%22accid%22%3a%226%22%2c%22roomtypeid%22%3a%225%22%7d%7d
above 1 stored value in cookie.
public responseentity < modelandview > savereservation(@requestbody string reservation, httpservletrequest request, httpservletresponse response) throws exception { cookie cookie = new cookie("tourreservation", urlencoder.encode(reservation, "utf-8")); cookie.setmaxage(24 * 60 * 60); cookie.setpath("/tour/reservation"); response.addcookie(cookie); list < ? > list = service.saveres(reservation); if (list.size() > 0) { ......... return new responseentity < modelandview > (model, httpstatus.ok); } return new responseentity < modelandview > (new modelandview("tour"), httpstatus.bad_request); }
how can list string in format? used stringescapeutils
, got error java.lang.illegalargumentexception: invalid character [34] present in cookie value
.
org.apache.commons.lang.stringescapeutils.unescapejava(reservation)
leave is. cookie value in javascript , use unescape(str) or decodeuricomponent(str) function decode it.
note: unescape()
deprecated may use decodeuricomponent()
instead.
Comments
Post a Comment