URLDecoder: Incomplete trailing escape (%) pattern问题处理

mac2022-06-30  19

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

________________________________________________________

最近在用的项目中,分页页面在导出excel抛出

 

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

 

该页面采用的是DWR分页,经过一番搜罗,终于修成正果.解决办法 大致意思都懂了,我们只需要将传入后台的参数字符在decode之前使用replaceAll('%','%')一下即可

Java代码   try {       pageTitle = java.net.URLDecoder.decode(pageTitle,"UTF-8");       sc = java.net.URLDecoder.decode(sc ,"UTF-8");   catch (UnsupportedEncodingException e) {         e.printStackTrace();  }    

 修正后代码如下:

 

Java代码   try {       pageTitle = java.net.URLDecoder.decode(pageTitle.replaceAll("%", "%"),"UTF-8");       sc = java.net.URLDecoder.decode(sc.replaceAll("%", "%") ,"UTF-8");   catch (UnsupportedEncodingException e) {         e.printStackTrace();  }    

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

 

特别注意:

 

有些时候导出excel时采用的是get方式导致URL字符串长度过长,改用POST方式可以解决以上问题。

 

使用js实现POST表单提交代码片段:

 

Js代码   function post(URL, PARAMS)  {              //创建一个临时表单      var tempForm = document.createElement("form");                 tempForm.action = URL;              tempForm.method = "post";              tempForm.style.display = "none";             //遍历各个参数,将文本域添加至表单中      for (var x in PARAMS)       {                  var opt = document.createElement("textarea");                  opt.name = x;                  opt.value = PARAMS[x];                  tempForm.appendChild(opt);              }              //将表单添加至当前页面中.      document.body.appendChild(tempForm);                //提交表单.      tempForm.submit();    }  

 

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

转载于:https://www.cnblogs.com/cuizhf/p/4212461.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)