IsValid (значение объекта) не реализовано этим классом

Я пытаюсь использовать getServletContext (). getRealPath ("/") , но я продолжаю получать эту ошибку:

не может найти символ символ: метод getServletContext () расположение: интерфейс javax.servlet.http.HttpSession String path = session.getServletContext (). GetRealPath ("/") + "layout / tile /" + reportPath; enter image description here

public ModelAndView handleRequest( HttpServletRequest request, HttpServletResponse response ) throws Exception {

        session = request.getSession();
        Map params = new HashMap();
        String reportPath = "maintenance/jasper/report01.jasper";
        exportToPDF( reportPath , response, params );

        return null;
    }

    protected void exportToPDF( String reportPath , HttpServletResponse response, Map jasperParams ) throws Exception {

            String path = session.getServletContext().getRealPath( "/" ) + "layout/tiles/" + reportPath ;

            if ( !new File( path ).exists() ) {
                throw new Exception( "The path doesn''t exist. 
" + path ); } InputStream input = new FileInputStream( path ); jasperParams.put( "REPORT_LOCALE", Locale.US ); JasperPrint jasper = JasperFillManager.fillReport( input , jasperParams, new JRBeanCollectionDataSource(Vehicles) ); response.setContentType( "application/pdf" ); ServletOutputStream output = response.getOutputStream(); JRExporter exporter = new JRPdfExporter(); exporter.setParameter( JRExporterParameter.JASPER_PRINT, jasper ); exporter.setParameter( JRExporterParameter.OUTPUT_STREAM, output ); exporter.exportReport(); output.close(); }

Ты хоть представляешь, почему это происходит?

Спасибо, Ритеш, я сделал то, что ты мне сказал, но теперь я получаю новое сообщение

enter image description here

------ EDIT --------

проверяя свой файл dispatcher-servlet.xml, я обнаружил, что он немного отличается от кода, показанного на этом web . Я не знаю, как это может повлиять на мой проект, но мне хотелось бы знать, есть ли другой подход к получению того же результата, что и при использовании сеанса. getServletContext () .getRealPath ("/")


    


    
        
            /WEB-INF/tiles.xml
        
    

8
задан eddy 30 January 2011 в 15:18
поделиться