JSP页面不显示中文字符

时间:2018-09-21 02:02:50

标签: java jsp pdf utf-8 response

下面的代码运行良好,该网页以.jsp扩展名结尾,并且该页面看起来像pdf。但是我无法在网页上打印出汉字。我尝试将CharacterEncoding设置为UTF-8,但仍然无法打印汉字。我从另一篇文章中读到,此外,响应,缓冲区和编写器也需要启用汉字。

Document document = new Document(PageSize.A4);
PdfWriter writer;
ByteArrayOutputStream buffer = new ByteArrayOutputStream();

document.setMargins(50, 50, 140, 50);
writer = PdfWriter.getInstance(document, buffer);
HeaderFooter event = new HeaderFooter( ); 

writer.setBoxSize("art", new Rectangle(36, 54, 559, 488));
writer.setPageEvent(event);
document.open();
insertHtmlContentToDocument( strContent,  document,  writer );
document.close();
writer.close(); 

filename = "FinancialReport2015.pdf";
response.reset();
response.setHeader("Cache-Control","no-cache"); 
response.setHeader("Pragma","no-cache"); 
response.setDateHeader ("Expires", 0);
**response.setContentType(" application/pdf; charset=UTF-8");       
response.setCharacterEncoding("UTF-8");**
response.addHeader("Content-Disposition","filename="+filename);

byte[] bytes =  buffer.toByteArray();  
response.getOutputStream().write(bytes);
response.flushBuffer(); 

out.clear();    
out=pageContext.pushBody(); 
buffer.close();

0 个答案:

没有答案