Birt supports custom export Chinese names
BIRT is an open source report system based on Eclipse developed for Web applications based on Java and JavaEE. Although it supports file export, it does not support dynamic customization of file names during export, especially in Chinese.
By default, Birt provides two ways to customize the name when exporting a file, as follows:
DefaultFilenameGenerator: the name of the report file. Suffix name TimestampFilenameGenerator: report file name + yyyyMMdd-HHmmss. Suffix name
If Birt implements the custom export file name, you need to implement the IFilenameGenerator API under the org.eclipse.birt.report.utility.filename package, as shown below:
Custom implementation of IFilenameGenerator interface public class CustomExportGenerator implements IFilenameGenerator {@ Override public String getFilename (String baseName, String fileExtension, String outputType, Map options) {return baseName + "." + fileExtension;}}
As you can see from the above code, the method in IFilenameGenerator does not provide a custom file name by default, which can only be obtained from the Map options parameter. Of course, if it is not too much trouble, you can override the getFilename interface.
Object obj = options.get ("httpRequest"); if (obj! = null & & obj instanceof RequestFacade) {RequestFacade request = (RequestFacade) obj; exportName = ParameterAccessor.getParameter (request, "_ _ filename");} configure Birt's export file generation class
Modify web.xml
BIRT_FILENAME_GENERATOR_CLASS org.eclipse.birt.report.utility.filename.CustomExportGenerator supports Chinese
File name: org.eclipse.birt.report.presentation.aggregation.layout.FramesetFragment
Method: doPreService (HttpServletRequest request, HttpServletResponse response)
Action:
String filename = ParameterAccessor.getExportFilename (new BirtContext (request, response), format, emitterId); String displayName = URLEncoder.encode (filename, "utf-8"); displayName = displayName .replace ("+", "% 20"); response.setCharacterEncoding ("utf-8"); response.setHeader ("contentType", "text/html; charset=utf-8") Response.setHeader ("Content-Disposition", / / $NON-NLS-1$ ParameterAccessor.htmlEncode (openType) + "; filename=\"+ ParameterAccessor.htmlEncode (displayName) +"\ "); modify the encoding of Tomcat
Access method:
Frameset?report=test.rptdesign&format=docx&__filename= test