Я получил простой логин на своей странице. После входа я отображаю данные с сервера, которые отображаются только после обновления страницы один раз.
Прежде чем я получу ошибку 500:
GET http://localhost:8080/getDesktop 500
angular.js:14800 Possibly unhandled rejection: ...
Мой код AngularJS следующий:
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope, $http, $window, $timeout){
//Username
$scope.user = "";
//Desktop
$scope.storage = [];
//Get username
$http.get("/loggeduser", {transformResponse: function(response){
return JSON.stringify(response);
}
}).then(function(response) {
$scope.user = response.data.substring(1, response.data.length-1);
});
//Show Desktop
$http.get("/getDesktop").then(function(response){
for(var i = 0; i<response.data.length; i++){
$scope.storage[i] = {name: response.data[i]};
}
return;
});
});
Backend:
//Returns Desktop
@GetMapping("/getDesktop")
public ArrayList<String> getDesktop() throws Exception {
ArrayList<String> itemNames = new ArrayList<>();
if(kdxF.getUser() != null) {
itemNames = kdxF.showDesktop();
// Just a function to return the Elements in an ArrayList if Strings
// If user is logged in
}else {
throw new Exception("Not logged in!");
}
return itemNames;
}
И я получаю сообщение «Не залогинен»