📄 getreportservlet.java
字号:
res.setHeader( "Cache-Control", "no-cache" ); res.setHeader( "Pragma", "no-cache" ); // calculate procent if( pages > 0 ) { int procent = ( page * 100 ) / pages; res.getWriter().print( procent ); } else { res.getWriter().print( -1 ); } } } // // Get report as Html file action // private void doHtmlAction( HttpServletRequest req, HttpServletResponse res, Long processId ) throws ServletException, IOException { long time = System.currentTimeMillis(); // Set MIME-type. res.setContentType( ServletHelper.CONTENT_TYPE_HTML ); // Do print. doPrint( req, res, processId ); // Ok. logger.INFO( "Convert report to HTML process completed. Time (ms) = " + ( System.currentTimeMillis() - time ) ); } // // Get report as Excel file action // private void doExcelAction( HttpServletRequest req, HttpServletResponse res, Long processId ) throws ServletException, IOException { long time = System.currentTimeMillis(); // Set MIME-type. res.setContentType( excelMimeType ); // Do print. doPrint( req, res, processId, EXPORTED_REPORT ); // Ok. logger.INFO( "Convert report to Excel process completed. Time (ms) = " + ( System.currentTimeMillis() - time ) ); } // // Get report as Word file action // private void doWordAction( HttpServletRequest req, HttpServletResponse res, Long processId ) throws ServletException, IOException { long time = System.currentTimeMillis(); // Set MIME-type. res.setContentType( wordMimeType ); // Do print. doPrint( req, res, processId, EXPORTED_REPORT ); // Ok. logger.INFO( "Convert report to Word process completed. Time (ms) = " + ( System.currentTimeMillis() - time ) ); } // ----------------------------------------------------------------- private methods // // Print report. // private void doPrint( HttpServletRequest req, HttpServletResponse res, Long processId ) throws ServletException, IOException { doPrint( req, res, processId, HTML_REPORT ); } private void doPrint( HttpServletRequest req, HttpServletResponse res, Long processId, int reportType ) throws ServletException, IOException { // Login. LogonSession ls = WebLoginManager.getLogonSession(req); // Get translet name String transletName = ServletHelper.getParamAsString( req, "transletName" ); // Get ReportBuilder object from the cache. ReportBuilder reportBuilder = getReportBuilderCache( req.getSession() ). getReportBuilder( processId ); if( reportBuilder == null ) { // Show "Not Found" screen. logger.ERROR( "Cannot find ReportBuilder for processID: " + processId ); reportNotFound( req, res, processId ); } else { // Generate and print report. Map transletParams = null; if( reportType == EXPORTED_REPORT ) { transletParams = new HashMap(); transletParams.put( ( Object ) "EXPORTED_REPORT", ( Object )new Integer( 1 ) ); } try { boolean isGzip = ZipFilter.isGZipSupported( req ); if (isGzip) { res.setHeader( "Content-Encoding", ServletHelper.CONTENT_TYPE_GZIP ); reportBuilder.print( transletName, transletParams, res.getOutputStream() ); } else { reportBuilder.print( transletName, transletParams, res.getWriter() ); } } catch( EQLException ex ) { logger.ERROR( ex ); throw new ServletException( ex ); } } } // // Show "Not Found" screen. // protected void reportNotFound( HttpServletRequest req, HttpServletResponse res, Long processId ) throws ServletException, IOException { res.setContentType( ServletHelper.CONTENT_TYPE_HTML ); req.getRequestDispatcher( notFoundUrl ).forward( req, res ); } // // Deserialize Report object. // private Report readReport( Long processId, HttpServletRequest req ) throws IOException { return( Report ) XMLHelper.getParsedObject( Report.class, req.getInputStream() ); } // // Get numeric ID postfix // private Long getId( HttpServletRequest req ) throws ServletException { Long id = null; String action = req.getPathInfo(); if( action != null ) { int pos = action.lastIndexOf( "/" ); if( pos > 0 && pos < ( action.length() - 1 ) ) { String s = action.substring( pos + 1 ); try { id = new Long( s ); } catch( NumberFormatException ex ) { throw new ServletException( "Bad ID: " + s ); } } } return id; } // // Get report builder cache. // protected ReportBuilderCache getReportBuilderCache( HttpSession session ) { ReportBuilderCache cache = ( ReportBuilderCache ) session.getAttribute( REPORT_BUILDER_CACHE_PARAM ); if( cache == null ) { cache = new ReportBuilderCache(); session.setAttribute( REPORT_BUILDER_CACHE_PARAM, cache ); } return cache; } /** * The method gets word mime type * @return String **/ public String getWordMimeType() { return wordMimeType; } // getWordMimeType(): String /** * The method gets excel mime type * @return String **/ public String getExcelMimeType() { return excelMimeType; } // getExcelMimeType(): String /** * The method gets getNotFoundURL string * @return String **/ public String getNotFoundURL() { return notFoundUrl; } // getNotFoundURL(): String // ----------------------------------------------------------------- inner class /** * <p>Storage for <code>ReportBuilder</code> objects</p> * @author [ALB] Baranov Andrey * @version $Revision: 1.1.1.1 $ $Date: 2005/09/12 15:30:45 $ */ public static class ReportBuilderCache implements Serializable, HttpSessionBindingListener { private Map cache = new HashMap(); public ReportBuilder getReportBuilder( Long processId ) { return( ReportBuilder ) cache.get( processId ); } public void putReportBuilder( ReportBuilder reportBuilder ) { cache.put( reportBuilder.getProcessId(), reportBuilder ); } public void removeReportBuilder( Long processId ) { cache.remove( processId ); } /** * Notifies the object that it is being bound to a HTTP session. * @param event session-binding event */ public void valueBound( HttpSessionBindingEvent event ) {} /** * Notifies the object that it is being unbound from a HTTP session. * @param event session-binding event */ public void valueUnbound( HttpSessionBindingEvent event ) { for( Iterator it = cache.keySet().iterator(); it.hasNext(); ) { Long processId = ( Long ) it.next(); ReportBuilder reportBuilder = getReportBuilder( processId ); // Cancel operation. try { reportBuilder.cancel(); } catch( Throwable t ) {} } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -