I am learning Angular.js. I tried to search many existing questions but could not find one matching question or answer.
I am sending a GET request to a java servlet and expecting an object from it. Here is the angular $http GET request
$http({
method:'GET',
url : '/JSONWebApp/json/?fqn=' + $scope.fqn
}).
success(function(data, status, header, config){
console.log('Success');
console.log("data - "+data);
console.log("status - " + status);
console.log("header - " + header);
console.log("config - " + config);
}).
error(function(data, status, header, config){
console.log('Error');
});
On java servlet, here is what I write in doGet method
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("Incoming Request URI : " + request.getRequestURI());
**User user = new User();
request.setAttribute("user", user);
RequestDispatcher view = request.getRequestDispatcher("/html/index.html");
view.forward(request, response);**
}
When the response is returned from this servlet, it goes to success of $http service in angular side. From where I will get the user object which I sent from server.
When I add the console.log to print the data, it prints the /html/index.html contents which is where I am forwarding.
Based on my research, my angular code is correct but I am not setting things correctly in java servlet.(Does this help - How to access json return values in angular.js action success callback)
Thanks in advance.