The arabic input parameter passed as like a junk i

2019-06-14 01:18发布

We were using JasperReports 4.6.0 and Java 1.6 to generate the PDF reports. It was working fine for parameters with text on English. If I pass the Arabic input parameter the input parameter passed as like a junk character hence I couldn't fetch the recordset. The same was working when I use JasperReports 3.7.6 and Java 1.5

My code:

JasperPrint print = null;
Runtime run = null;
String strJasperFile = "E:/DailyWork/FEB-2013/report2.jasper";
String strOutputFile = "E:/DailyWork/FEB-2013/report2.xls";
String printtime="";
Connection con = getSqlConnection();        
HashMap mpDetailSp = new HashMap(); 
mpDetailSp.put("parameter1", "B المهمات");
print = JasperFillManager.fillReport(strJasperFile, mpDetailSp, con);           
JRExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, strOutputFile);
exporter.exportReport();

Could you please advise me how to sort it out this problem?

2条回答
男人必须洒脱
2楼-- · 2019-06-14 01:28

Finally, I found out the solution for this problem. It was encoding setting in the Java 1.6 JVM. I had set the environment variable as like below to sort it out the problem

JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF8

It was resolved my problem. The input was given by the another forum post in statck overflow

https://stackoverflow.com/a/623036/770927

I thank to Edward Grech, He explained obvious reason and solution in the above post.

查看更多
冷血范
3楼-- · 2019-06-14 01:35

Not being the an expert in Jasper I can suppose that the problem is in the text encoding. I performed a short search and found this resource: http://www.adp-gmbh.ch/misc/tools/jasper/java.html

Please take a look in the template example and pay attention on line <?xml version="1.0" encoding="UTF-8"?> on top of the file. Does your file report2.jasper contain such line? Check it and include it if it is missing.

Additionally add line

exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");

I hope now all will work.

查看更多
登录 后发表回答