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
The most accurate way would be to Excecute javascript withing your java code. Hope the code below helps.
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
ScriptContext context = engine.getContext();
engine.eval("function decodeStr(encoded){"
+ "var result = unescape(encoded);"
+ "return result;"
+ "};",context);
Invocable inv;
inv = (Invocable) engine;
String res = (String)inv.invokeFunction("decodeStr", new Object[]{cookie.getValue()});