2013-05-08 60 views
5

我是一名開發人員,當Cookie包含元音變音字符(ä,ö,ü)時,我面臨以下例外情況,我嘗試了許多解決方案和配置,但沒有任何結果。當Cookie包含元音變音字符時,Tomcat 7異常

我用Tomcat7

任何解決方案,請

Feb 21, 2013 6:29:16 AM org.apache.coyote.http11.AbstractHttp11Processor process 
SEVERE: Error processing request 
java.lang.IllegalArgumentException: Control character in cookie value or attribute. 
    at org.apache.tomcat.util.http.CookieSupport.isHttpSeparator(CookieSupport.java:193) 
    at org.apache.tomcat.util.http.Cookies.getTokenEndPosition(Cookies.java:488) 
    at org.apache.tomcat.util.http.Cookies.processCookieHeader(Cookies.java:291) 
    at org.apache.tomcat.util.http.Cookies.processCookies(Cookies.java:168) 
    at org.apache.tomcat.util.http.Cookies.getCookieCount(Cookies.java:106) 
    at org.apache.catalina.connector.CoyoteAdapter.parseSessionCookiesId(CoyoteAdapter.java:919) 
    at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:688) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:402) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579) 
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1600) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) 
    at java.lang.Thread.run(Thread.java:722) 
+0

見http://stackoverflow.com/questions/6108207/definite-guide-to-valid-cookie-values:http://tomcat.apache.org/tomcat-8.0-doc/config/cookie-processor.html

通過在你的conf/context.xml中啓用它和http://stackoverflow.com/questions/1969232/allowed-characters-in-cookies。一種解決方案是用UTF-8編碼你的字符串,並使用base64來獲得可接受的ascii字符。 – 2013-05-08 21:59:04

回答

0

使用UTF-8編碼。

你可以將它設置全局:

java -Dfile.encoding=UTF-8 

或者本地:

System.setProperty("file.encoding", "UTF-8"); 

byte inbytes[] = new byte[1024]; 
FileInputStream fis = new FileInputStream("the.location.of.your.cookie"); 
fis.read(inbytes); 

另外,如果你是手動編輯餅乾,不保存。相反,使用UTF-8當量,這是

System.out.println("\u00c4"); 



Chars Unicode 
------------------------------ 
Ä, ä \u00c4, \u00e4 
Ö, ö \u00d6, \u00f6 
Ü, ü \u00dc, \u00fc 
ß  \u00df 
2

根據你需要升級到Tomcat 8.0.15(或更高版本),另外一個問題的註釋,並啓用RFC 6455 cookie的處理器。 這裏記載:

<Context> 
    <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor" /> 
</Context> 
相關問題