反饋已提交
網絡繁忙
报表已集成到 Web 页面中,通过在页面传递参数至报表中时,会发现有时某些参数值,传递到报表中是显示为问号(???)或乱码等等一系列不能正常显示的情况。
这是由于浏览器和报表服务器的编码不同,字符多次进行编码转换时出现错误导致字符的显示出现乱码,尤其是中日韩文和特殊字符更容易出现乱码问题。
详细的编码原理可参考文档: 编码
在给报表服务器发送请求之前,使用 JavaScript 先对 URL 编码,然后再向服务器提交。避免了不同的操作系统、不同的浏览器、不同的网页字符集,导致完全不同的编码结果。
因为JavaScript 的输出总是一致的,所以就保证了服务器得到的数据是格式统一的。
对 URL 中的中文,包含模板名、参数名字和参数值,进行 encodeURIComponent 或者 encodeURI 编码。
所以 encodeURIComponent 比 encodeURI 编码的范围更大。 实际例子来说,encodeURIComponent 会把 http:// 编码成 http%3A%2F%2F 而 encodeURI 却不会。
这里对整个 URL 进行编码,因此使用 encodeURL,如下所示:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><script Language="JavaScript"> function frOpen() { window.location=encodeURI("http://localhost:8075/webroot/decision/view/report?viewlet=GettingStarted.cpt&地区=华东")} </script></head><body><input type="button" value="字符转换1" onclick="frOpen()"></body></html>
当然也可以使用encodeURIComponent只对参数进行编码:
window.location="http://localhost:8075/webroot/decision/view/report?viewlet="+encodeURIComponent("中文.cpt")
如果是以 Form 表单把参数提交到报表里面,在提交前调用 encodeURIComponent 进行编码转换,如下:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><script>function autoSubmit() { var Region1 = document.getElementById('Region'); //获取到参数 Region 所在文本框 Region1.value = encodeURIComponent(Region.value); //对值参数值进行编码转化 Region1.name = encodeURIComponent("地区"); //对参数控件名编码转换,如果参数名字为英文,则不需要此操作 document.FRform.submit();}</script><body><form name=FRform method=post action="http://localhost:8075/webroot/decision/view/report?viewlet=doc/Primary/Parameter/Parameter.cpt"><input type="text" id="Region" name="地区" value="华东"><input type="button" name="show" value= "查看" onclick="autoSubmit()"/></body></html>
如果在需要进行编码的 URI 的参数中包含特殊字符,比如%,#,$,=,&,/,?,+,@等字符时,使用 encodeURIComponent 对这些特殊字符进行编码。
例如参数值是”%华%“这样的字符,完整代码如下:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><script Language="JavaScript"> function frOpen() { window.location="http://localhost:8075/webroot/decision/view/report?viewlet=GettingStarted.cpt&"+encodeURIComponent("地区")+"="+encodeURIComponent("%华%") } </script></head><body><input type="button" value="字符转换1" onclick="frOpen()"></body></html>
文 檔回 饋
滑鼠選中內容,快速回饋問題
滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。
不再提示
10s後關閉