如何用Java';那是杰索纳雷吗?
我正在尝试使用JSONObject和JSONArray将json数组从我的Javaservlet(使用mysql服务器)发送到html页面。数组已成功发送到html页面,但表本身未获取任何内容如何用Java';那是杰索纳雷吗?,java,html,angularjs,json,servlets,Java,Html,Angularjs,Json,Servlets,我正在尝试使用JSONObject和JSONArray将json数组从我的Javaservlet(使用mysql服务器)发送到html页面。数组已成功发送到html页面,但表本身未获取任何内容 {"Info":[{"Name":"Jack","Lastname":"Nilson","Birthday":"1980-10-10","Address":"Nowhere","State": "ABC","ZIP":"999"}]} 这是我总是在html页面的第一行得到的,而表本身却什么也没有得到 {
{"Info":[{"Name":"Jack","Lastname":"Nilson","Birthday":"1980-10-10","Address":"Nowhere","State": "ABC","ZIP":"999"}]}
这是我总是在html页面的第一行得到的,而表本身却什么也没有得到
{"Info":[{"Name":"Jack","Lastname":"Nilson","Birthday":"1980-10-10","Address":"Nowhere","State": "ABC","ZIP":"999"}]}
Servlet(doPost)
AngularJS:
<script type="text/javascript">
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.post("InfoServletPath")
.then(function (response) {
$scope.Info = response.data.Info;
});
});
</script>
<body>
<form action="InfoServletPath" method="POST">
<div ng-app="myApp" ng-controller="customersCtrl">
<table id="pInfo">
<thead>
<tr>
<th width="10%">Name</th>
<th width="10%">Lastname</th>
<th width="10%">Birthday</th>
<th width="10%">Address</th>
<th width="10%">STATE</th>
<th width="10%">Zip</th>
</tr>
</thead>
<tr ng-repeat="row in Info">
<td> {{ row.Name }} </td>
<td> {{ row.Lastname }} </td>
<td> {{ row.Birthday }} </td>
<td> {{ row.Address }} </td>
<td> {{ row.State }} </td>
<td> {{ row.ZIP }} </td>
</tr>
</table>
</div>
</div>
</form>
</body>
var-app=angular.module('myApp',[]);
app.controller('customersCtrl',函数($scope,$http){
$http.post(“InfoServletPath”)
.然后(功能(响应){
$scope.Info=response.data.Info;
});
});
HTML:
<script type="text/javascript">
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.post("InfoServletPath")
.then(function (response) {
$scope.Info = response.data.Info;
});
});
</script>
<body>
<form action="InfoServletPath" method="POST">
<div ng-app="myApp" ng-controller="customersCtrl">
<table id="pInfo">
<thead>
<tr>
<th width="10%">Name</th>
<th width="10%">Lastname</th>
<th width="10%">Birthday</th>
<th width="10%">Address</th>
<th width="10%">STATE</th>
<th width="10%">Zip</th>
</tr>
</thead>
<tr ng-repeat="row in Info">
<td> {{ row.Name }} </td>
<td> {{ row.Lastname }} </td>
<td> {{ row.Birthday }} </td>
<td> {{ row.Address }} </td>
<td> {{ row.State }} </td>
<td> {{ row.ZIP }} </td>
</tr>
</table>
</div>
</div>
</form>
</body>
名称
姓氏
生日
地址
陈述
拉链
{{row.Name}
{{row.Lastname}
{{row.生日}}
{{row.Address}}
{{row.State}}
{{row.ZIP}}
我已经有这个问题好几天了,老实说,我似乎找不到任何解决问题的办法。我在互联网和stackoverflow中发现的唯一一件事就是如何用json文件中的AngularJS填充表格。我可能在设置angularJS脚本代码时遇到问题,但我真的不知道在这种情况下如何设置。非常感谢您对这个问题的任何帮助
注意:我没有使用JSP。根据您上次的评论,您在写回响应时似乎缺少
内容类型:application/json
。你的角度设置看起来很好。没有问题
JSONObject json1 = new JSONObject();
json1.put("Info", jarr);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json1.toString());
rs.close();
根据您上次的评论,在写回响应时,您似乎缺少
内容类型:application/json
。你的角度设置看起来很好。没有问题
JSONObject json1 = new JSONObject();
json1.put("Info", jarr);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json1.toString());
rs.close();
您能否在承诺/响应中共享
console.log(response)
和console.log(response.data)
的输出get@Searching我很确定问题可能出在我的angularjs代码上,但我不完全确定问题出在哪里。Hmmdid您是否检查浏览器开发工具网络选项卡以查看您从ur jsp发送的数据是否正确格式化?你的错误是说它不是。对不起,在电话里打字。我刚检查过,你是对的。它不显示。但为什么它会把它扔到网页上呢?你能在你的承诺/回应中分享console.log(response)
和console.log(response.data)
的输出吗?@搜索“无效的json回应”是我想要的get@Searching我很确定问题可能出在我的angularjs代码上,但我不完全确定问题出在哪里。Hmmdid您是否检查浏览器开发工具网络选项卡以查看您从ur jsp发送的数据是否正确格式化?你的错误是说它不是。对不起,在电话里打字。我刚检查过,你是对的。它不显示。但为什么它会把它扔到网页上呢?我在doPost函数的一开始就有它。setContentType(“application/json;charset=UTF-8”);嗯..试一试,看看console.log是否仍然输出相同的错误?发送一个空的json对象而不填充数据,看看是否存在格式问题。即使在分别设置它们之后,您是否也会收到相同的错误?等等,为什么要使用$.post而不是$.get?让我们来看看。我在doPost函数的最开始部分已经介绍了它。setContentType(“application/json;charset=UTF-8”);嗯..试一试,看看console.log是否仍然输出相同的错误?发送一个空的json对象而不填充数据,看看是否存在格式问题。即使在分别设置它们之后,您是否仍会收到相同的错误?等等,为什么要使用$.post而不是$.get?让我们来看看。