title: Why getservletcontext isn't found?
body: <p>I'm trying to use <strong>getServletContext().getRealPath( "/" )</strong> , but I keep getting this error: </p>
  
  <p><strong><em>cannot find symbol
  symbol  : method getServletContext()
  location: interface javax.servlet.http.HttpSession
        String path = session.getServletContext().getRealPath("/") + "layout/tiles/" + reportPath ;</em></strong>
  <img src="https://i.stack.imgur.com/RNXQX.jpg" alt="enter image description here"></p>
  
  <pre><code>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. &lt;/br&gt;" + 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();
  
  
      }
  </code></pre>
  
  <p>Have you any idea why this is happening ?</p>
  
  <p>Thanks Ritesh, I did what you told me, but now I get a new message</p>
  
  <p><img src="https://i.stack.imgur.com/L2DpR.jpg" alt="enter image description here"></p>
  
  <p>------EDIT--------</p>
  
  <p>checking my dispatcher-servlet.xml  I found that it's kind of different from the code shown on this <a href="http://netbeans.org/kb/68/web/quickstart-webapps-spring.html" rel="noreferrer">web</a> . I don't know how  it could affect my project, but what I do like to know if there's a different approach to getting the same result as using session.<strong>getServletContext()</strong>.getRealPath( "/" )</p>
  
  <pre><code>&lt;bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt;
      &lt;property name="viewClass"
                value="org.springframework.web.servlet.view.tiles2.TilesView" /&gt;
  &lt;/bean&gt;
  &lt;bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"&gt;
      &lt;property name="definitions"&gt;
          &lt;list&gt;
              &lt;value&gt;/WEB-INF/tiles.xml&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>