String.getBytes()方法中的中文编码问题

String.getBytes()方法中的中文编码问题-java认证-认证考试-网页教学网

String的getBytes()方法是得到一个字串的字节数组,这是众所周知的。但特别要注意的是,本方法将返回该操作系统默认的编码格式的字节数组。如果你在使用这个方法时不考虑到这一点,你会发现在一个平台上运行良好的系统,放到另外一台机器后会产生意想不到的问题。

JasperReport – PrinterJob can’t detect the new default printer

sdf
Reflections & Reference Objects – PrinterJob can’t detect the new default printer in JSP/Servlet

Hi,

I solved my problem but I’m not sure it applies to your problems too.

I was using JRPrintServiceExporter and it does not use the default print service, but the first print service returned by PrintServiceLookup.lookupPrintServices(DocFlavor, AttributeSet).

Simply adding this line:

PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();

And adding that as an export parameter:

exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, defaultPrintService);

Solves the problem.

example code is below:

JasperPrint print = JasperFillManager.fillReport(fileName, null, con);
                //JasperPrintManager.printReport(print, false);
                PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
                PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();

                //printServiceAttributeSet.add(MediaSizeName.ISO_A4);
                //print to your printer by printer name
                // printServiceAttributeSet.add(new PrinterName(“Microsoft Office Document Image Writer", null));
                printRequestAttributeSet.add(new Copies(iCopies[i]));

                // print to default printer
                JRPrintServiceExporter exporter = new JRPrintServiceExporter();
                PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
                exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, defaultPrintService);

                exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
                exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
                exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printServiceAttributeSet);
                exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
                exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);

                //System.out.println(“export to printer");

                exporter.exportReport();

How to debug JasperReport in NetBeans

JasperForge: JasperServer JasperServer 的討論區

1. add log4j.properties file in Source Packages

log4j.properties example

# To change this template, choose Tools | Templates
# and open the template in the editor.
log4j.rootLogger=INFO, A2
log4j.appender.A2=org.apache.log4j.ConsoleAppender
log4j.appender.A2.layout=org.apache.log4j.SimpleLayout

log4j.logger.net.sf.jasperreports=debug
log4j.logger.net.sf.jasperreports.engine.query.JRJdbcQueryExecuter=debug