JSP cookies[loop].getValue()在@为变量时中断

JSP cookies[loop].getValue()在@为变量时中断,jsp,cookies,Jsp,Cookies,我已将cookie设置为电子邮件地址,用于低级别登录。当我得到cookie的值时,它不会返回超过@符号的任何内容 例如: cookie值=name@domain.com" cookie get value='variable=cookie[loop].getValue' 返回='name' 有没有办法解决这个问题 是否可能转义字符?在cookie中,@是无效字符。我建议对cookie值进行URL编码和URL解码 Cookie cookie = new Cookie(name, URLEncode

我已将cookie设置为电子邮件地址,用于低级别登录。当我得到cookie的值时,它不会返回超过@符号的任何内容

例如:

cookie值=name@domain.com"

cookie get value='variable=cookie[loop].getValue'

返回='name'

有没有办法解决这个问题

是否可能转义字符?

在cookie中,@是无效字符。我建议对cookie值进行URL编码和URL解码

Cookie cookie = new Cookie(name, URLEncoder.encode(value, "UTF-8"));
// ...

饼干声明 ===============================================================

    String a = URLDecoder.decode(cks[i].getValue());

这将使您获得cookie所有字符,包括@,在@

之后感谢您的时间,我收到一个错误“无法重新选择指向URL的符号…”但在使用代码时:Cookie cookieUserId=new CookiecookieUserId,urlcoder.encodeemailAddress,UTF-8;这是否意味着我需要安装URLEcoder?我在ApacheTomcat/4.1.40上运行这个程序,直到最近它才成为一个问题;或者让你的IDE自动完成它?。
enter code here
   String str="name@domain.com";
    str=URLEncoder.encode(str);
    Cookie ck2=new Cookie("email",str);
    String a = URLDecoder.decode(cks[i].getValue());