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);