URLDecoder: Incomplete trailing escape (%) pattern問題處理

來源:互聯網
上載者:User

標籤:

http://blog.csdn.net/yangbobo1992/article/details/10076335

________________________________________________________

最近在用的項目中,分頁頁面在匯出excel拋出

 

java.lang.IllegalArgumentException: URLDecoder: Incomplete trailing escape (%) pattern

 

該頁面採用的是DWR分頁,經過一番搜羅,終於修成正果.解決辦法

 大致意思都懂了,我們只需要將傳入背景參數字元在decode之前使用replaceAll(‘%‘,‘%25‘)一下即可

Java代碼  
  1. try {  
  2.      pageTitle = java.net.URLDecoder.decode(pageTitle,"UTF-8");  
  3.      sc = java.net.URLDecoder.decode(sc ,"UTF-8");   
  4. } catch (UnsupportedEncodingException e) {    
  5.      e.printStackTrace();  
  6. }    

 修正後代碼如下:

 

Java代碼  
  1. try {  
  2.      pageTitle = java.net.URLDecoder.decode(pageTitle.replaceAll("%", "%25"),"UTF-8");  
  3.      sc = java.net.URLDecoder.decode(sc.replaceAll("%", "%25") ,"UTF-8");   
  4. } catch (UnsupportedEncodingException e) {    
  5.      e.printStackTrace();  
  6. }    

部分引用來自: http://dwr.2114559.n2.nabble.com/Exception-URLDecoder-Incomplete-trailing-escape-pattern-td5396332.html

 

特別注意:

 

有些時候匯出excel時採用的是get方式導致URL字串長度過長,改用POST方式可以解決以上問題。

 

使用js實現POST表單提交程式碼片段:

 

Js代碼  
  1. function post(URL, PARAMS)  
  2. {          
  3.     //建立一個暫存資料表單  
  4.     var tempForm = document.createElement("form");       
  5.       
  6.     tempForm.action = URL;          
  7.     tempForm.method = "post";          
  8.     tempForm.style.display = "none";   
  9.       
  10.     //遍曆各個參數,將文本域添加至表單中  
  11.     for (var x in PARAMS)   
  12.     {          
  13.         var opt = document.createElement("textarea");          
  14.         opt.name = x;          
  15.         opt.value = PARAMS[x];          
  16.         tempForm.appendChild(opt);          
  17.     }    
  18.       
  19.     //將表單添加至當前頁面中.  
  20.     document.body.appendChild(tempForm);      
  21.       
  22.     //提交表單.  
  23.     tempForm.submit();    
  24. }  

 

也可參照此方法解決:http://blog.csdn.net/zhensoft163/article/details/7298161

URLDecoder: Incomplete trailing escape (%) pattern問題處理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.