Overview
Problem
After the report is integrated into a web page, you can pass parameters to the report. However, sometimes certain parameter values appear incorrectly as question marks (???), garbled characters, or other unreadable symbols during the passing.
Cause
Due to the difference in encoding between the browser and the report server, errors in multiple encoding conversions of characters lead to the garbled display of characters, which is more likely to occur in Chinese, Japanese, Korean, and special characters.
Implementation Method
You can use JavaScript to encode the URL before sending the request to the report server, and then submit it to the server. In this way, completely different encoding results due to different operating systems, different browsers, and different web character sets can be avoided.
The consistent output of JavaScript ensures that the server receives uniformly formatted data.
You can encode the Chinese characters in the URL, including the template name, parameter name, and parameter value by encodeURIComponent or encodeURI.
| Method | Non-coded Characters | Application Scenario | Example |
|---|---|---|---|
| encodeURI | ASCII letters, numbers, ~!@#$&*()=:/,;?+' | You can use encodeURI when you need to encode the entire URL and use that URL. | encodeURI("http://localhost:8075/webroot/decision/view/report?viewlet=Chinese.cpt") |
| encodeURIComponent | ASCII letters, numbers, ~!*()' | You can use encodeURIComponent when you need to encode parameters in a URL. | "http://localhost:8075/webroot/decision/view/report?viewlet="+encodeURIComponent("Chinese.cpt") Note: |
So encodeURIComponent has a larger encoding scope than encodeURI. In the actual scenario, you can use encodeURIComponent instead of encodeURI to encode http:// as http%3A%2F%2F.
Example
Encoding Chinese in URLs
You can use encodeURL to encode the entire URL, as shown in the following:
<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&Region = East China")
}
</script>
</head>
<body>
<input type="button" value="character conversion1" onclick="frOpen()">
</body>
</html>You can use encodeURIComponent to encode the parameters only:
window.location="http://localhost:8075/webroot/decision/view/report?viewlet="+encodeURIComponent("Chinese.cpt")
Encoding Chinese in Form Forms
You can use encodeURIComponent for encoding conversion before submitting the parameters to the report as a Form form, as shown in the following:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script>
function autoSubmit() {
var Region1 = document.getElementById('Region');//To obtain the text box where the parameter Region is located.
Region1.value = encodeURIComponent(Region.value);//To convert the parameter value by encoding.
Region1.name = encodeURIComponent("Region");//To convert the widget name (except English) of the parameter by encoding.
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="Region" value="East China">
<input type="button" name="show" value= "view" onclick="autoSubmit()"/>
</body>
</html>Encoding Special Symbols
You can use encodeURIComponent to encode special symbols such as %, #, $, =, /, ?, and @ included in the parameters in the URI to be encoded.
Note:You can use the following codes to encode the symbol %China%.
<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("Region")+"="+encodeURIComponent("%China%")
}
</script>
</head>
<body>
<input type="button" value="character conversion1" onclick="frOpen()">
</body>
</html>