标签:redirect generator protoc basename repo The isp clip splay
BIRT 是以 Java 和 JavaEE 为基础为 Web 应用程序开发的基于 Eclipse 的开源报表系统,虽然支持文件导出功能,但不支持导出时动态自定义文件名称,尤其不支持中文。Birt默认提供了两种导出文件时自定义名称的方法,如下:
Birt若实现自定义导出文件名称,需要实现org.eclipse.birt.report.utility.filename包下的IFilenameGenerator接口,具体操作如下:
public class CustomExportGenerator implements IFilenameGenerator {
@Override
public String getFilename( String baseName, String fileExtension, String outputType, Map options) {
return baseName + "." + fileExtension;
}
}
从上面的代码看出,IFilenameGenerator 中的方法默认没有提供自定义文件名称,这时候只能够从Map options参数中获取,当然如果不嫌麻烦的话,也可以重写getFilename接口。
Object obj = options.get("httpRequest");
if(obj !=null && obj instanceof RequestFacade){
RequestFacade request = (RequestFacade)obj;
exportName = ParameterAccessor.getParameter(request,"__filename");
}
修改web.xml
<context-param>
<param-name>BIRT_FILENAME_GENERATOR_CLASS</param-name>
<param-value>org.eclipse.birt.report.utility.filename.CustomExportGenerator</param-value>
</context-param>
文件名称:org.eclipse.birt.report.presentation.aggregation.layout.FramesetFragment
方法: doPreService( HttpServletRequest request, HttpServletResponse response )
操作:
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 )
+ "\"" );
<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
标签:redirect generator protoc basename repo The isp clip splay
原文地址:https://blog.51cto.com/favccxx/2430816