It is disgusting to encounter this exception. In Tomcat7 environment, this exception will be raised if the user’s name appears in Chinese when logging in. After the exception is caused, the user who cannot log in normally needs to delete the browser’s cookie information. Later, I checked the Internet and found out that the problem was Chinese transcoding. The abnormal information is as follows:
java.lang.IllegalArgumentException: Control character in cookie value or attribute.
at org.apache.tomcat.util.http.CookieSupport.isV0Separator(CookieSupport.java:155)
at org.apache.tomcat.util.http.Cookies.processCookieHeader(Cookies.java:323)
at org.apache.tomcat.util.http.Cookies.processCookies(Cookies.java:157)
at org.apache.tomcat.util.http.Cookies.getCookieCount(Cookies.java:98)
at org.apache.catalina.connector.CoyoteAdapter.parseSessionCookiesId(CoyoteAdapter.java:913)
at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:683)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:400)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:304)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Cookie is encoded by Unicode in Chinese and ASCII in English when storing the value, so the data needs to be transcoded when storing the Chinese value, and the data also needs to be transcoded when storing the value.
There are two solutions, one is a Cookie written in Java, and the other is a Cookie written in JavaScript.
The solution is as follows:
Java:
Encode: URLEncoder. Encode (name, “UTF-8”);
Decode.decode (name, “UTF-8”);
Decode.decode (name, “UTF-8”);
JavaScript:
Code: the escape (name);/encodeURI(name);
decode: unescape(name);/decodeURI(name);
The Servlet setting cookies to view the article: http://blog.csdn.net/twilight041132/article/details/46482983
Read More:
- Illegalargumentexception error when adding cookie to response
- Python’s json.loads Invalid control character
- Parsing the exception of storing JSON string in cookie
- Tomcat error parsing HTTP request header
- [vue/no-parsing-error]Parsing error: control-character-in-input-stream.eslint-plugin-vue
- Tomcat9 Error: Could not find or load main class org.apache.catalina.startup.Bootstrap
- Springboot startup error: java.lang.IllegalArgumentException : Property ‘sqlSessionFactory’ or ‘sqlSessionTempla
- Remove M Characters “Control M” or “^M” or “CTRL M” Characters in a UNIX file
- Three ways of adding cookie by scratch
- Syntax error: unexpected character after line continuation character
- [resolved] error: Java: illegal character: ‘\ ufef’ or error: Java: class, interface or enum required
- After modifying the Tomcat configuration file in development, the modified configuration file will be automatically restored after ecplise starts Tomcat
- ‘Conversion failed when converting date and/or time from character string.DB-Lib error message 241,
- Some uncommon problems and solutions of cookie
- tomcat Issues org.apache.catalina.LifecycleException: Failed to start component
- Error in Maven packaging web project: webxml attribute is required (or pre existing WEB-INF)/ web.xml if executing in update)
- Solving syntax error: unexpected character after line continuation character
- A child container failed during start Tomcat error prompt
- Error: (serious: a child container failed during start) (server component failed to start so Tomcat is unable)
- Chrome Broswer V98 Can not manually add cookies locally, refresh cannot be retained, and the cookie item is red