title: Getting current session object in Java
body: <p>Can I access session object from within a function where request object is not present?</p>
  
  <p>I know in Java we access session like this:  </p>
  
  <pre><code>HttpSession session = request.getSession(true);
  </code></pre>
  
  <p>But what if we want to access session when request object is not present?  </p>
  
  <h2>Is it possible? is there an alternate way to get session object?</h2>
  
  <p>Edit</p>
  
  <p>I have a servlet</p>
  
  <pre><code>public class ABC extends HttpServlet
  {
      public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException
      {
               ..........
               ...........
          myFun1(x,y,z);  
      }
  
        private void myFun1(int x, int y,long z)
        {
              .........
              myFun2(a,b);    
         }
  
        private void myFun2(int a,String b)
        {
              .........
  
              //      Need Session here
         }
  
  }
  </code></pre>