java.lang.IllegalArgumentException: Control character in cookie value or attribute
来源:互联网 发布:淘宝电商是什么意思 编辑:程序博客网 时间:2024/04/29 18:16
I am trying to set the unicode value inside the cookie but it doesn't accept this and throws Exception. I have checked the hexadecimal value of the string and it is correct but throws Exception while adding to a cookie.
private void fnSetCookieValues(HttpServletRequest request,HttpServletResponse response) { Cookie[] cookies=request.getCookies(); for (int i = 0; i < cookies.length; i++) { System.out.println(""+cookies.length+"Name"+cookies[i].getName()); if(cookies[i].getName().equals("DNString")) { System.out.println("Inside if:: "+cookies[i].getValue()+""+cookies.length); try { String strValue; strValue = new String(request.getParameter("txtIIDN").getBytes("8859_1"),"UTF8"); System.out.println("Cookie Value To be stored"+strValue); for (int j = 0; j < strValue.length(); j++) { System.out.println("Code Point"+Integer.toHexString(strValue.codePointAt(j))); } Cookie ck = new Cookie("DNString",strValue); response.addCookie(ck); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
java.lang.IllegalArgumentException: Control character in cookie value or attribute.
when adding the cookie to response object. I am using Tomcat 7 and Java 7 as the runtime environment.
Version 0 cookie values are restrictive in allowed characters. It only allows URL-safe characters. This covers among others the alphanumeric characters (a-z, A-Z and 0-9) and only a few lexical characters, including -
, _
, .
, ~
and %
. All other characters are invalid in version 0 cookies.
Your best bet is to URL-encode those characters. This way every character which is not allowed in URLs will be percent-encoded in this form %xx
which is valid as cookie value.
So, when creating the cookie do:
Cookie cookie = new Cookie(name, URLEncoder.encode(value, "UTF-8"));// ...
And when reading the cookie, do:
String value = URLDecoder.decode(cookie.getValue(), "UTF-8");// ...
- java.lang.IllegalArgumentException: Control character in cookie value or attribute.
- java.lang.IllegalArgumentException: Control character in cookie value or attribute.
- java.lang.IllegalArgumentException: Control character in cookie value or attribute.
- java.lang.IllegalArgumentException: Control character in cookie value or attribute
- java.lang.IllegalArgumentException: Control character in cookie value or attribute.
- java.lang.IllegalArgumentException: Control character in cookie value or attribute
- java.lang.IllegalArgumentException: Control character in cookie value or attribute.
- java.lang.IllegalArgumentException: Control character in cookie value or attribute
- servlet 设置cookie遇到java.lang.IllegalArgumentException: Control character in cookie value or attribute
- IllegalArgumentException: Control character in cookie value or attribute Tomcat7中文写入cookie时引发异常
- Jsp 出现异常IllegalArgumentException:Control character in cookie value or attribute解决方法
- Tomcat报错Control character in cookie value or attribute.
- tomcat7中cookie写入中文引发Control character in cookie value or attribute异常
- tomcat7中cookie写入中文引发Control character in cookie value or attribute异常
- java.lang.IllegalArgumentException: An invalid character [44] was present in the Cookie value
- 【Java Web】control character in cookie value orattribute
- java Cookie 存储汉字报Control character in cookie value, consider BASE64 encoding your value
- Control character in cookie value, consider BASE64 encoding your value
- 第9周项目4-广义表算法库及应用(2)
- C# 加载xml文档文件及加载xml字符串
- Python 小技巧——<Cookbook>读书笔记(2)deque和heapq
- Java设计模式——线程安全的单件模式
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher I POJ 3080
- java.lang.IllegalArgumentException: Control character in cookie value or attribute
- Xcode8支持iOS7真机测试
- Log4j使用教程
- caffe层解读系列——hinge_loss
- OpenCasCade的显示模块(visulation模块)概要说明
- Android自学笔记-5-click事件的四种写法
- PHP: session.gc_maxlifetime vs. session.cookie_lifetime
- 分布式系统中利用zookeeper集群实现微服务主备切换代码片段(C语言版)
- 默认墨迹天气 下雪效果