首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

jasperreport生成excel中文乱码问题

2014-01-26 
%@ page contentTypetext/htmlcharsetGBK %%@ page importnet.sf.jasperreports.engine.* %%@

<%@ page contentType="text/html;charset=GBK" %>
  <%@ page import="net.sf.jasperreports.engine.*" %>
  <%@ page import="net.sf.jasperreports.engine.util.*" %>
  <%@ page import="net.sf.jasperreports.engine.export.*" %>
  <%@ page import="java.util.*" %>
  <%@ page import="java.io.*" %>
  <%@ page import="java.sql.*" %>
  <%@ page import="javax.naming.*" %>
  <%@ page import="javax.sql.*" %>
 
  <%
  Context ctx = new InitialContext();
  DataSource ds = (DataSource)ctx.lookup("moia");
  Connection conn = ds.getConnection();
 
  HashMap params = new HashMap();
  params.put("", "");
  //String rptName = request.getParameter("rptName");
  //JasperPrint jasperPrint = JasperFillManager.fillReport("/" + rptName + ".jasper", params, conn);
  File business_rpt = new File(application.getRealPath("snts/cwszcs/reports/dklxsrb.jasper"));
  out.println(business_rpt.toString());
  JasperPrint jasperPrint=null;
  try{
  jasperPrint=JasperFillManager.fillReport(business_rpt.getPath(),params,conn);
  }catch(JRException e){
  e.printStackTrace();
  }
 
  //String rptType = request.getParameter("rptType");
  String rptType="tabular";
 
  if("tabular".equals(rptType))
  {
  JRExporter exporter = null;
  //String exportTo = request.getParameter("exportTo");
  String exportTo="Excel (*.xls)";
  if("HTML (*.html)".equals(exportTo))
  {
  exporter = new JRHtmlExporter();
  exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
  }
  else if("PDF (*.pdf)".equals(exportTo))
  {
  exporter = new JRPdfExporter();
  response.setContentType("application/pdf");
  }         

热点排行