jasperreport(5)

2020-02-22 12:56

publicvoid destroy() {

super.destroy(); // Just puts \ // Put your code here }

publicvoid doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

String view=request.getParameter(\ if(view==null || view.trim().length()==0) return;

if(view.equalsIgnoreCase(\ if(view.equalsIgnoreCase(\ if(view.equalsIgnoreCase(\ if(view.equalsIgnoreCase(\ }

privatevoid doHtml(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException { ServletContext context=getServletContext();

//String jrxml=context.getRealPath(\ /* try {

String jasper=context.getRealPath(\\

String html=\ JasperRunManager.runReportToHtmlFile(jasper,context.getRealPath(html),new HashMap(),getConn());

response.sendRedirect(request.getContextPath()+html);

} catch (JRException e) { e.printStackTrace(); } */

String reportDir=context.getRealPath(\ String jasper=reportDir+\

response.setContentType(\ response.setCharacterEncoding(\ Map map=new HashMap(); Map imageMap=new HashMap(); map.put(\

map.put(\ map.put(\

request.getSession().setAttribute(\ Connection conn=getConn(); try {

// JasperPrint print=JasperFillManager.fillReport(jasper,map,new TestBeanDataSource());

JasperPrint print=JasperFillManager.fillReport(jasper,map,conn); // JasperPrint print=JasperFillManager.fillReport(jasper,map,new JREmptyDataSource());

JRHtmlExporter exporter = new JRHtmlExporter();

request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,print);

exporter.setParameter(JRExporterParameter.JASPER_PRINT, print); exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, resp

onse.getWriter());

exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP,imageMap);

exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath()+\

exporter.setParameter(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);

exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.TRUE);

exporter.exportReport();

} catch (JRException e) {

StringWriter sw=new StringWriter(); PrintWriter pw=new PrintWriter(sw); e.printStackTrace(pw);

response.setContentType(\

response.getOutputStream().print(sw.toString()); } finally { if(conn!=null) try {

if(!conn.isClosed()) conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }

privatevoid doPdf(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException { ServletContext context=getServletContext();

//String jrxml=context.getRealPath(\ String reportDir=context.getRealPath(\ String jasper=reportDir+\

response.setContentType(\ Map map=new HashMap(); map.put(\

map.put(\ map.put(\ Connection conn=getConn(); try {

OutputStream os=response.getOutputStream(); InputStream is=new FileInputStream(jasper);

JasperRunManager.runReportToPdfStream(is,os,map,conn); // JasperRunManager.runReportToPdfStream(is,os,map,new TestBeanDataSource());

os.flush(); os.close();

} catch (JRException e) {

StringWriter sw=new StringWriter(); PrintWriter pw=new PrintWriter(sw); e.printStackTrace(pw);

response.setContentType(\

response.getOutputStream().print(sw.toString()); } finally { if(conn!=null)

try {

if(!conn.isClosed()) conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }

privatevoid doExcel(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException { ServletContext context=getServletContext();

String reportDir=context.getRealPath(\ String jasper=reportDir+\

response.setContentType(\

response.setHeader(\xls\

Map map=new HashMap();

map.put(\//设置参数,导出类型为xls

map.put(\// 设置参数,图片路径

map.put(\ Connection conn=getConn(); try {

JasperReport report=(JasperReport)JRLoader.loadObject(jasper); try {//设置上边距,左边距,右边距,下边距为0

java.lang.reflect.Field margin = JRBaseReport.class.getDeclaredField(\

margin.setAccessible(true); margin.setInt(report, 0);


jasperreport(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:精编新版《安全员》考试题库800题(答案)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: