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


后台提示:

嚴重: Error processing request
java.lang.IllegalArgumentException: Control character in cookie value or attribute.
at org.apache.tomcat.util.http.CookieSupport.isV0Separator(CookieSupport.java:165)
at org.apache.tomcat.util.http.Cookies.processCookieHeader(Cookies.java:349)
at org.apache.tomcat.util.http.Cookies.processCookies(Cookies.java:176)
at org.apache.tomcat.util.http.Cookies.getCookieCount(Cookies.java:106)...

————————————————————————————————————————————————————\

項目簡述:在js中操作cookie時出現的異常(Jquery中依然能用)

基本代碼如下:(已修改)

 if("Administrator"==result.data.username){//管理員設計
                             document.cookie="username="+escape('系統管理員');
                            // $.cookie('username','系統管理員');
                         }else{//普通員工設計                             
                             document.cookie="username="+escape(result.data.username);     
                             document.cookie="postId="+result.data.postId;//職務Id                    
                             document.cookie="induction_time="+result.data.induction_time;//入職時間
                             document.cookie="monthlyleave="+result.data.monthlyleave;//當月假期
                         }
                        
                         document.cookie="userId="+result.data.id;//
                         document.cookie="identification="+result.data.identification;//標記
                        
                        

異常分析:

1.cookie值有問題

2.cookie中編碼有問題,一般都是中文那里

修改:在js中調用escape(“中文”),進行編碼,

在讀取cookie時,用unescape(document.cookie);進行解碼

補充:

有的是在服務器端代碼遇到的問題,請到服務器端去修改編碼(服務器端不用escape)。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM