I have tomcat6 and use open report application in it. when i export any report as excel or pdf, it doesn't support arabic language. Please can anyone help me? you can find below jsp page code.
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@page import="org.efs.openreports.util.DisplayProperty"%>
<%@page import="org.efs.openreports.objects.Report"%>
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<s:include value="Banner.jsp" />
<s:if test="report == null || !report.isDisplayInline()">
<a class="back-link img-report-small" href="reportList.action"><s:text name="link.back.reports"/></a>
<a class="back-link img-group-small" href="reportGroup.action"><s:text name="link.back.groups"/></a>
<br/>
<s:actionerror/>
<div align="center">
<div class="important img-queryreport" id="instructions"><s:property value="report.name"/></div>
</div>
</s:if>
<div align="center">
<s:set name="results" value="results" scope="request" />
<s:set name="properties" value="properties" scope="request" />
<s:set name="report" value="report" scope="request" />
<% DisplayProperty[] displayProperties = (DisplayProperty[]) request.getAttribute("properties");
request.setCharacterEncoding("UTF-8");
Report report = (Report) request.getAttribute("report");%>
<display:table name="results" class="displayTag" sort="list" export="true" pagesize="20" requestURI="queryReportResult.action?tab=PRODUCTIVITY" excludedParams="org.apache.struts.taglib.html.TOKEN">
<% for (int i=0; i < displayProperties.length; i++) { %>
<display:column property="<%=displayProperties[i].getName()%>" title="<%=displayProperties[i].getDisplayName()%>" sortable="true" headerClass="sortable" />
<% } %>
<display:setProperty name="export.pdf" value="true"/>
<display:setProperty name="export.xml.filename" value="<%=report.getName() + ".xml"%>"/>
<display:setProperty name="export.pdf.filename" value="<%=report.getName() + ".pdf"%>"/>
<display:setProperty name="export.csv.filename" value="<%=report.getName() + ".csv"%>"/>
<display:setProperty name="export.excel.filename" value="<%=report.getName() + ".xls"%>"/>
</display:table>
<s:if test="#session.user.scheduler">
<s:text name="queryReport.scheduleReport"/>
<a href="reportOptions.action?reportId=<%=report.getId()%>&submitSchedule=true&exportType=3">CSV</a> |
<a href="reportOptions.action?reportId=<%=report.getId()%>&submitSchedule=t开发者_高级运维rue&exportType=1">Excel</a> |
<a href="reportOptions.action?reportId=<%=report.getId()%>&submitSchedule=true&exportType=0">PDF</a>
</s:if>
</div>
<s:if test="report == null || !report.isDisplayInline()">
<s:include value="Footer.jsp" />
</s:if>
help me quickly please...
I got a similar issue under JBoss using Displaytag 1.2 picked from a Stripes MVC application.
When the database (MySQL) was giving strings containing Scandinavian language characters encoded in UTF-8, then the CSV and Excel exporting of those tables was corrupted i.e. the downloaded file contained no data or a small amount of useless corrupted data.
I think the main issue, data related, was regarding Finnish characters' encodings which are in ISO-8859-1 but not in UTF-8 (cfr. http://en.wikipedia.org/wiki/ISO/IEC_8859-1).
The fix that is working for me was to:
adding this to the Stripes Action Bean:
getContext().getResponse().setCharacterEncoding("UTF-8"); getContext().getResponse().setContentType("application/vnd.ms-excel;charset=UTF-8");
adding this to the corresponding JSP:
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
After this I am succesfully able to download CSV and Excel files from a Displaytag table containing data encoded with UTF-8 characters from Scandinavian languages.
After searching i found solution for this case:
You should Add
response.setContentType("application/vnd.ms-excel;charset=Cp1256");
instead of:
request.setCharacterEncoding("UTF-8");
in <% DisplayProperty .....> line
for benefit
We are using DisplayTag 1.1.1 and we had a problem with special character encoding (UTF-8) in Excel/CSV export. After some search's we were able to fix the issue by adding BOM before export string to writeExport() in TableTag.java class.
Ex:
JspWriter lOut = pageContext.getOut();
...
lOut.write('\ufeff');
lOut.write(pExportString);
This works well (display special characters correctly) except in xls output, all data displayed in one cell in Excel 2010 although CSV output displayed correctly. \t - TAB separator didn't work after adding BOM. But if we replace \t with Comma(,), it works as expected in Excel 2010.
精彩评论