title: How to access java servlet session attribute in angular js application
body: <p>How to access servlet session attribute in angular js application, in the example the ProductServlet is setting the products in a session attribute, how to acess this variable in the AngularJs application, what is the equivalent of this</p>
  
  <pre><code>public class ProductServlet extends HttpServlet {
  .....
  ...
      List&lt;Products&gt; products = getProducts();// Return the List of the products
      if (session.getAttribute("userName") == null) {
              session.setAttribute("products", products);
          }
  ......
  ......
  }
  </code></pre>
  
  <p>My Angular JS controller</p>
  
  <pre><code> function ProductController($scope, $http)
      {
        $scope.user = {};
  
        $scope. GetProducts = function() 
        {
          $http({
            method: 'POST',
            url: 'http://localhost:8080/Products',
            headers: {'Content-Type': 'application/json'},
            data:  $scope.user
          }).success(function (data) 
            {
              $scope.status=data;
            });
        };
      }
  </code></pre>
  
  <p>The HTML</p>
  
  <p>
  
    
      
      
    </p>
  
  <pre><code>&lt;body&gt;
      &lt;form ng-controller="ProductController" ng-submit="GetProducts()"&gt;
      &lt;legend&gt;Get Productsr&lt;/legend&gt;
  
  
        &lt;button class="btn btn-primary"&gt;Get Products&lt;/button&gt;
        &lt;br/&gt;
        &lt;label&gt;DISPLAY the List of products&lt;/label&gt;
      &lt;/form&gt;
    &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>