Salve, sto cercando di capire come passare dei dati JSON dalla seguente servlet :
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter())
{
eliminacode.Connessione conn = new eliminacode.Connessione();
ArrayList<ClienteBean>listaClienti = conn.elencatutti();
response.setContentType("application/json");
JSONObject obj = new JSONObject();
obj.put("data", listaClienti);
String json = new Gson().toJson(obj);
response.getWriter().write(json);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
a questa pagina 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.3.8/angular.min.js"></script>
</head>
<body ng-app="ATP_PLAYERS">
<div ng-controller="atpController">
<h5>riceerca</h5>
<table>
<thead>
<tr>
<th>cf</th>
<th>nomeme</th>
<th>E-mail</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in atp">
<td>{{item.cf}}</td>
<td>{{item.name}}</td>
<td>{{item.email}}</td>
</tr>
</tbody>
</table>
</div>
<script language="javascript" type="text/javascript">
angular.module('ATP_PLAYERS', [])
.controller('atpController', function ($scope, $http) {
$http.get('http://localhost:8080/com.pic1/Angular').success(function (data, status, headers, config) {
$scope.atp = data;
});
});
</script>
</body>
</html>
Ho verificato il file Json ed è corretto ma quando passo i dati mi da quest' errore :
SyntaxError: Unexpected token S in JSON at position 0
at JSON.parse (<anonymous>)
non capisco cosa succede non penso che sia un problema della servlet penso si un problema di angularjs qualcuno mi sa spiegare l'errore grazie