I am trying to use getServletContext (). getRealPath ("/") , but I keep getting this error:
cannot find symbol symbol: getServletContext () method location: javax.servlet.http.HttpSession interface String path = session.getServletContext (). GetRealPath ("/") + "layout / tiles /" + reportPath; 
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. </br>" + 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(); }
Do you have any idea why this is happening?
Thanks Ritesh, I did what you told me, but now I get a new message

------ EDIT --------
checking my dispatcher-servlet.xml I found that it is slightly different from the code shown on this web . I donโt know how this can affect my project, but I like to know if there is a different approach to getting the same result as when using the session. getServletContext () .getRealPath ("/")
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" /> </bean> <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> <property name="definitions"> <list> <value>/WEB-INF/tiles.xml</value> </list> </property> </bean>
java spring-mvc servlets
eddy
source share