gpt4 book ai didi

javascript - servlet 不通过 angularJS 发送响应

转载 作者:行者123 更新时间:2023-11-28 00:01:31 25 4
gpt4 key购买 nike

我正在尝试运行 website 中的代码但我没有得到我应该得到的结果。我在 Eclipse 上开发了该项目,并且在 Web 内容文件夹上有一个 html 页面,在/src/AngularGET 文件夹下有一个名为“AtpPlayers”的 servlet。我相信我没有插入正确的网址。 请问你能帮帮我吗 ?

这里是 servlet AtpPlayers.java 的代码

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {   
response.setContentType("application/json;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println("[{\"name\": \"Nadal, Rafael (ESP)\", \"email\": \"nadalrafael@gmail.com\", \"rank\": \"1\"},"
+ "{\"name\": \"Djokovic, Novak (SRB)\", \"email\": \"djokovicnovak@gmail.com\", \"rank\": \"2\"},"
+ "{\"name\": \"Federer, Roger (SUI)\", \"email\": \"federerroger@gmail.com\", \"rank\": \"3\"},"
+ "{\"name\": \"Wawrinka, Stan (SUI)\", \"email\": \"wawrinkastan@gmail.com\", \"rank\": \"4\"},"
+ "{\"name\": \"Ferrer, David (ESP)\", \"email\": \"ferrerdavid@gmail.com\", \"rank\": \"5\"}]");
}

}

和html代码

<!DOCTYPE html>

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script type="text/javascript">
angular.module('ATP_PLAYERS', [])
.controller('atpController', function ($scope, $http) {
$http.get('/AngularGET/AtpPlayers').success(function (data, status, headers, config) {
$scope.atp = data;
});
});
</script>
</head>

<body data-ng-app="ATP_PLAYERS">
<div data-ng-controller="atpController">
<h5>Loading ATP players from a Servlet</h5>
<table>
<thead>
<tr>
<th>Rank</th>
<th>Name</th>
<th>E-mail</th>
</tr>
</thead>
<tbody>

<tr data-ng-repeat="item in atp">
<td>{{item.rank}}</td>
<td>{{item.name}}</td>
<td>{{item.email}}</td>
</tr>
</tbody>

</table>
</div>

</body> </html>

最佳答案

找到了!而不是 $http.get('/AngularGET/AtpPlayers') 我不得不把 $http.get('AtpPlayers')

关于javascript - servlet 不通过 angularJS 发送响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31762115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com