我已经使用 Waffle 使用 Jsp 和 Tomcat 获取当前登录用户。但是我如何使用 Angularjs 复制相同的内容。
我在 Git 中使用了 Demo 代码来制作华夫饼https://dblock.github.com/waffle/
请帮忙,因为我对如何让 Angular 应用程序调用 jsp 并将用户名取回 Angular 应用程序感到困惑。
我已经使用 Waffle 使用 Jsp 和 Tomcat 获取当前登录用户。但是我如何使用 Angularjs 复制相同的内容。
我在 Git 中使用了 Demo 代码来制作华夫饼https://dblock.github.com/waffle/
请帮忙,因为我对如何让 Angular 应用程序调用 jsp 并将用户名取回 Angular 应用程序感到困惑。
在我看来,检查用户的最佳方法是使用 AngularJS http 拦截器。
$httpProvider.interceptors.push(function ($q) {
return {
'request': function(response) {
},
'response': function (response) {
// TODO Create check for user authentication. With every request send "headers"
return response;
},
'responseError': function (reject) {
// Forbidden
if(reject.status == 403) {
console.log('This page is forbidden.');
window.location = '/';
// Unauthorized
} else if(reject.status == 401) {
console.log("You're not authorized to view this page.");
window.location = '/';
}
return $q.reject(reject);
}
};
});
在“响应”中编写一个函数来检查用户的 http 标头或类似的东西。AngularJS 中的拦截器
这个拦截器将在您对数据库的每次调用中运行,如果返回错误,您也可以在那里处理。