我正在学习 Angular.js。我尝试搜索许多现有问题,但找不到一个匹配的问题或答案。
我正在向一个 java servlet 发送一个 GET 请求,并期待一个对象。这是角度 $http GET 请求
$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');
});
在 java servlet 上,这是我在 doGet 方法中写的
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);**
}
当从这个 servlet 返回响应时,它会在角度方面成功 $http 服务。我将从哪里获取从服务器发送的用户对象。
当我添加 console.log 来打印数据时,它会打印我要转发的 /html/index.html 内容。
根据我的研究,我的角度代码是正确的,但我没有在 java servlet 中正确设置。(这有帮助 -如何在 angular.js 操作成功回调中访问 json 返回值)
提前致谢。