您好,登錄后才能下訂單哦!
BIRT 是以 Java 和 JavaEE 為基礎(chǔ)為 Web 應(yīng)用程序開發(fā)的基于 Eclipse 的開源報表系統(tǒng),雖然支持文件導(dǎo)出功能,但不支持導(dǎo)出時動態(tài)自定義文件名稱,尤其不支持中文。
Birt默認(rèn)提供了兩種導(dǎo)出文件時自定義名稱的方法,如下:
Birt若實現(xiàn)自定義導(dǎo)出文件名稱,需要實現(xiàn)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 中的方法默認(rèn)沒有提供自定義文件名稱,這時候只能夠從Map options參數(shù)中獲取,當(dāng)然如果不嫌麻煩的話,也可以重寫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"/>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。