DWR分页页面导出时后台使用URLDecoder.decode抛出异常

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

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

 

该页面采用的是DWR分页,经过一番搜罗,终于修成正果.解决办法

 大致意思都懂了,我们只需要将传入后台的参数字符在decode之前使用replaceAll('%','%25')一下即可

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

 修正后代码如下:

 

try {
     pageTitle = java.net.URLDecoder.decode(pageTitle.replaceAll("%", "%25"),"UTF-8");
     sc = java.net.URLDecoder.decode(sc.replaceAll("%", "%25") ,"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表单提交代码片段:

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

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值