我正在尝试运行此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>
答案 0 :(得分:1)
答案 1 :(得分:0)
<!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>
&#13;