Un-escape JavaScript escaped value in Java

前端 未结 4 1498
醉梦人生
醉梦人生 2021-01-18 23:05

In our web service we set a cookie through JavaScript wich we read again in Java (Servlet)

However we need to escape the value of the cookie because it may contain i

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 23:56

    Client JavaScript/ECMAScript:

    encodeURIComponent(cookie_value) // also encodes "+" and ";", see http://xkr.us/articles/javascript/encode-compare/
    

    Server Java:

    String cookie_value = java.net.URLDecoder.decode(cookie.getValue());
    

    I'll add further discoveries to my blog entry.

提交回复
热议问题