Cookie读写问题 - jQuery到JSP [英] Cookie read and write issue- jQuery to JSP

查看:100
本文介绍了Cookie读写问题 - jQuery到JSP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 jQuery Cookie插件创建Cookie:

using jQuery cookie plugin I create cookie:

$.cookie('uom', '1-23-235(K)');

当我从JSP读取它时,它只返回以下

When I read it from JSP, it Return me only the following

1-23-235

如果我在创建Cookie时删除括号,例如

and if I remove parentheses while creating cookies, such as

$.cookie('uom', '1-23-235 K');

那么没有问题!所有工作都很好。

then there is no problem! All working is fine.

如何克服这个问题,因为用户可以输入任何符号,如括号

How can I overcome this because user can enter any symbol like parentheses

推荐答案

尝试对您设置为Cookie的字符进行转义(也称为URL编码):

Try escaping (aka URL-encoding) the strings you set as cookies:

在JS端:

escape(cookie);

在Java端:

String result = URLDecoder.decode(cookie, "UTF-8");

这篇关于Cookie读写问题 - jQuery到JSP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆