1

I use Servlet+JasperReport to generate a pdf file with variable filename. But the filename doesn't display correctly if the variable fileName (at line six) contains non-english characters.

I got the file as ---.pdf or --english--or--number--.pdf.

Here is my code:

byte[] pdf = JasperRunManager.runExportToPdf(report, params, datasource);
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();

response.setContentType("application/pdf");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + ".pdf\"");

ServletOutputStream sos = responser.getOutputStream();

sos.write(pdf);
sos.flush();
sos.close();
context.responseComplete();

I did lots of searching, but couldn't find a solution to display non-english characters correctly. It seems a bit stupid and pretty easy thing to do, but I want your answer. Thank you.

environment:debian(testing unstable)+jsf++maven+spring+hibernate+java7.

Oleg
  • 9,341
  • 2
  • 43
  • 58
Teifi
  • 713
  • 2
  • 12
  • 20
  • possible duplicate of [Java localized filenames](http://stackoverflow.com/questions/4736807/java-localized-filenames) – tpeczek Nov 12 '12 at 13:40

0 Answers0