2
如何訪問angular js應用程序中的servlet會話屬性,例如ProductServlet將產品設置爲會話屬性,如何在AngularJs應用程序中訪問此變量,這是如何在angular js應用程序中訪問java servlet會話屬性
public class ProductServlet extends HttpServlet {
.....
...
List<Products> products = getProducts();// Return the List of the products
if (session.getAttribute("userName") == null) {
session.setAttribute("products", products);
}
......
......
}
我的角度JS控制器
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;
});
};
}
的HTML
相當於
<body>
<form ng-controller="ProductController" ng-submit="GetProducts()">
<legend>Get Productsr</legend>
<button class="btn btn-primary">Get Products</button>
<br/>
<label>DISPLAY the List of products</label>
</form>
</body>
</html>
這意味着所有在JSP-Servlet模型上運行的傳統應用程序必須遷移 – anish 2014-10-08 04:48:52