项目中做自动登录和保存密码时,Cookie报错Java.lang.IllegalArgumentException,上google查了下

在http://hi.baidu.com/xtxycy/blog/item/a614635168c61b14367abe98.html看到了说明:

今天完成了一个用cookie记录用户名的功能,之前没有考虑到用户的用户名如果是中文会是怎样的影响。就在测试的时候,用了一个中文去登陆,发现报错,错误信息如下:

java.lang.IllegalArgumentException: Control character in cookie value, consider BASE64 encoding your value

后来上网查了下,才知道原来是转码的问题,解决方法如下;

J2EE Doc里面的,cookies只支持ASCII字符,而且不能有逗号,分号,
空白。或者以$开头。名字在创建后不能改变。如果要存储中文的,先用URLEcode编码,在存入,取出的时候,用decode解码。。。

在保存cookie之前把值编码下:

  1. URLEncoder.encode(cookieValue, "UTF-8");

取cookie值时解码:

    1. URLDecoder.decode(localCookieValue, "UTF-8");

Cookie存储中文报错:java.lang.IllegalArgumentException: Control character in cookie value or attribute.(转)的更多相关文章

  1. 在浏览器访问Tomcat的时候报错java.lang.IllegalArgumentException: Control character in cookie value or attribute.

    出现这种情况的原因就是因为cookie中存在中文或者特殊符号造成的,应为Tomcat7不支持 解决方法: 1,首先必须先删除本地的cookie,否则项目无法访问 2,然后调整编码就行了

  2. tomcat使用cookies缓存的时候中文报错解决办法 java.lang.IllegalArgumentException: Control character in cookie value or attribute.

    报错出现 java.lang.IllegalArgumentException: Control character in cookie value or attribute. at org.apac ...

  3. cookie遇到java.lang.IllegalArgumentException: Control character in cookie value or attribute

    java.lang.IllegalArgumentException: Control character in cookie value or attribute. 该异常说明cookie中的val ...

  4. 异常:java.lang.IllegalArgumentException: Control character in cookie value or attribute.

    后台提示: 严重: Error processing requestjava.lang.IllegalArgumentException: Control character in cookie va ...

  5. HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalArgumentException: Control character in cookie value or attribute.

    HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalArgumentException: ...

  6. 后台报错java.lang.IllegalArgumentException: Invalid character found in the request target.

    报错: Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level. java.lang ...

  7. 创建Cookie抛出异常:java.lang.IllegalArgumentException: Control character in cookie value

    调用Cookie对象的构造函数可以创建Cookie.Cookie对象的构造函数有两个字符串参数:Cookie名字和Cookie值.   名字和值都不能包含空白字符以及下列字符:[ ] ( ) < ...

  8. 反射报错java.lang.IllegalArgumentException: wrong number of arguments

    class Person{ private String name ; private String sex ; public Person(){ System.out.println("c ...

  9. mybatis mapper.xml 写关联查询 运用 resultmap 结果集中 用 association 关联其他表 并且 用 association 的 select 查询值 报错 java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mybatis.map

    用mybaits 写一个关联查询 查询商品表关联商品规格表,并查询规格表中的数量.价格等,为了sql重用性,利用 association 节点 查询 结果并赋值报错 商品表的mapper文件为Gooo ...

随机推荐

  1. sshd_config配置 详解

    原文:http://blog.licess.org/sshd_config/ # 1. 关于 SSH Server 的整体设定,包含使用的 port 啦,以及使用的密码演算方式 Port 22 # S ...

  2. iOS导航栏-导航栏透明

    设置一张透明图片:nav_bargound.png  //导航栏背景     [self.navigationController.navigationBar setBackgroundImage:[ ...

  3. JDBC 程序的常见错误及调试方法

    详细介绍:http://dev.mysql.com/doc/refman/5.5/en/error-handling.html http://dev.mysql.com/doc/refman/5.5/ ...

  4. (6)妈的终于找到能用的nehe sdk了

    在网上下载了有十多个,终于找到一个能用的了 下面是下载地址: http://download.csdn.net/detail/jason_bourn/681620#comment 泪奔啊~

  5. 如何理解 MySQL 中的 <=> 操作符?

    问题 : 我在看以前的一个开发者的代码时看到 WHERE p.name <=> NULL 在这个查询语句中 <=>符号是什么意思啊?是不是和 =号是一样啊?还是一个语法错误啊? ...

  6. 初学Ajax(二)

    $.get()和$.post() .load()方法是局部方法,因为它需要一个包含元素的jQuery对象作为前缀.而$.get()和$.post()是全局方法,无须指定某个元素.对于用途而言,.loa ...

  7. jquery常见问题

    1.下面哪种说法是正确的? 您的回答:jQuery 是 JavaScript 库 2.jQuery 使用 CSS 选择器来选取元素? 您的回答:错误 正确答案:正确 3.jQuery 的简写是? 您的 ...

  8. Gradle Goodness: Skip Building Project Dependencies

    If we use Gradle in a multi-module project we can define project dependencies between modules. Gradl ...

  9. Textures

    LPDIRECT3DVERTEXBUFFER9 g_VertexBuffer=NULL; //顶点缓存 LPDIRECT3DTEXTURE9 g_Texture=NULL;//纹理对象 bool In ...

  10. java开发--struts2 标签库使用

    在工程中使用struts2标签 一.struts2标签定义文件在struts2-core-2.0.11.1\META-INF 下面,文件名为struts-tags.tld 二.如果工程使用了servl ...