admin管理员组文章数量:1415698
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
public class ProductServlet extends HttpServlet {
.....
...
List<Products> products = getProducts();// Return the List of the products
if (session.getAttribute("userName") == null) {
session.setAttribute("products", products);
}
......
......
}
My Angular JS controller
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;
});
};
}
The 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>
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
public class ProductServlet extends HttpServlet {
.....
...
List<Products> products = getProducts();// Return the List of the products
if (session.getAttribute("userName") == null) {
session.setAttribute("products", products);
}
......
......
}
My Angular JS controller
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;
});
};
}
The 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>
Share
Improve this question
asked Oct 8, 2014 at 4:29
anishanish
7,44814 gold badges84 silver badges153 bronze badges
1 Answer
Reset to default 4You cannot just access server-side data (such as attributes) from Javascript running in the browser.
You'd have to create some web service to expose this data (for example to JSON GET requests).
And if you do that, make sure that no one unauthorized can access this information.
本文标签: javascriptHow to access java servlet session attribute in angular js applicationStack Overflow
版权声明:本文标题:javascript - How to access java servlet session attribute in angular js application - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745238425a2649176.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论