使用CORS跨域REST / Jersey Web服务(Cross domain REST/Jersey web services with CORS)
我想用CORS(跨源资源共享)制作跨域REST Web服务。 我正在使用泽西图书馆提供服务。
我需要知道
从服务器端的角度来看,我需要做哪些代码/配置更改?
如何从HTML5 / js调用这些服务。
谢谢
I want to make Cross domain REST web services with CORS(Cross-Origin Resource Sharing). I am using Jersey Libraries for making services.
I need to know
What code/configuration changes i need to do from server side perspective?
How to invoke this services from HTML5/js.
Thanks
原文:https://stackoverflow.com/questions/9928266
更新时间:2024-01-15 08:01
最满意答案
您可以使用一个
ng-repeat
并使用customers[$index]
访问客户对象数组。请看下面的演示或这个jsfiddle 。
angular.module('App', []) .controller("myCtrl", function($scope){ $scope.tickets = [ {code:'1', city:'Istanbul', value:10.0}, {code:'2', city:'London', value:50.0}, {code:'3', city:'Paris', value:30.0} ]; $scope.customers = [ {name:'Customer1', age:36}, {name:'Customer2', age:42}, {name:'Customer3', age:28} ]; $scope.array = []; $scope.init = function(){ var k = 0; for(; k < $scope.tickets.length && k < $scope.customers.length; k++) $scope.array.push({ticket:$scope.tickets[k], customer:$scope.customers[k]}); for(; k < $scope.tickets.length; k++) $scope.array.push({ticket:$scope.tickets[k], customer:{name:'',age:''}}); for(; k < $scope.customers.length; k++) $scope.array.push({ticket:{code:'',city:'',name:''}, customer:$scope.customers[k]}); }; });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="App" ng-controller="myCtrl" ng-init="init()"> <h2>table with js mapping</h2> <table border=1> <thead> <tr> <th>Position</th> <th>Ticket</th> <th>Customer</th> </tr> </thead> <tbody ng:repeat="element in array"> <tr><td align=center>{{$index}}</td> <td align=center> {{element.ticket.code}}<br/> <strong>{{element.ticket.city}}</strong><br/> <em>{{element.ticket.value | currency}}</em> </td> <td align=center> {{element.customer.name}}<br/> {{element.customer.age}} </td> </tr> </tbody> </table> <h2>table with ng-repeat</h2> <table border=1> <thead> <tr> <th>Position</th> <th>Ticket</th> <th>Customer</th> </tr> </thead> <tbody ng:repeat="ticket in tickets"> <tr><td align=center>{{$index}}</td> <td align=center> {{ticket.code}}<br/> <strong>{{ticket.city}}</strong><br/> <em>{{ticket.value | currency}}</em> </td> <td align=center> {{customers[$index].name}}<br/> {{customers[$index].age}} </td> </tr> </tbody> </table> </div>
You could use one
ng-repeat
and access your customers object array withcustomers[$index]
.Please have a look at the demo below or in this jsfiddle.
angular.module('App', []) .controller("myCtrl", function($scope){ $scope.tickets = [ {code:'1', city:'Istanbul', value:10.0}, {code:'2', city:'London', value:50.0}, {code:'3', city:'Paris', value:30.0} ]; $scope.customers = [ {name:'Customer1', age:36}, {name:'Customer2', age:42}, {name:'Customer3', age:28} ]; $scope.array = []; $scope.init = function(){ var k = 0; for(; k < $scope.tickets.length && k < $scope.customers.length; k++) $scope.array.push({ticket:$scope.tickets[k], customer:$scope.customers[k]}); for(; k < $scope.tickets.length; k++) $scope.array.push({ticket:$scope.tickets[k], customer:{name:'',age:''}}); for(; k < $scope.customers.length; k++) $scope.array.push({ticket:{code:'',city:'',name:''}, customer:$scope.customers[k]}); }; });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="App" ng-controller="myCtrl" ng-init="init()"> <h2>table with js mapping</h2> <table border=1> <thead> <tr> <th>Position</th> <th>Ticket</th> <th>Customer</th> </tr> </thead> <tbody ng:repeat="element in array"> <tr><td align=center>{{$index}}</td> <td align=center> {{element.ticket.code}}<br/> <strong>{{element.ticket.city}}</strong><br/> <em>{{element.ticket.value | currency}}</em> </td> <td align=center> {{element.customer.name}}<br/> {{element.customer.age}} </td> </tr> </tbody> </table> <h2>table with ng-repeat</h2> <table border=1> <thead> <tr> <th>Position</th> <th>Ticket</th> <th>Customer</th> </tr> </thead> <tbody ng:repeat="ticket in tickets"> <tr><td align=center>{{$index}}</td> <td align=center> {{ticket.code}}<br/> <strong>{{ticket.city}}</strong><br/> <em>{{ticket.value | currency}}</em> </td> <td align=center> {{customers[$index].name}}<br/> {{customers[$index].age}} </td> </tr> </tbody> </table> </div>
相关问答
更多-
您应该查看$http服务的请求/响应转换器: $http : //docs.angularjs.org/api/ng.$http 请求/响应变换器只是在内容发送/回传给调用者之前可以调用的函数。 您可以在全局范围内(针对所有请求/响应)和每个请求指定转换函数: 要在本地覆盖这些转换,请将转换函数指定为config对象的transformRequest和/或transformResponse属性。 要全局覆盖默认转换,请覆盖$ httpProvider的$ httpProvider.defaults.tran ...
-
最后,我成功地用链式地图解决了这个问题。 val arrayOfFrames = filteredFramePaths.collect.map(row => { Media( row.getInt(1), sqlContext.read.json("/mnt/" + row(5)) ) } ).map(a => {Media(a.id, a.content.withColumn("frame", explode($"frames")).select ($"frame.*"))} ).map ...
-
你应该将两个承诺一起归还,你不能在一个函数中返回两个。 在这种情况下, $q.all会有所帮助。 码 //inject $q in service function this.getNames = function () { var data = $http.get('data,json', { cache: false}); var names = $http.get('names.json', { cache: false}); return $q.all([data, na ...
-
这种方法足够可靠吗? 只有当对象被创建的方式可靠地按照相同的顺序将对象添加到对象中(或者在对象上定义自己的toJSON )。 JSON.stringify遵循JSON.stringify中定义的属性顺序 ,该顺序对创建属性的顺序非常敏感,因此两个等效对象可以具有不同的JSON表示,因为属性顺序可能不同: var o1 = {a: 1, b: 2}; // Adds `a` before `b` var o2 = {b: 2, a: 1}; // Adds `b` before `a` var json1 ...
-
您可以使用一个ng-repeat并使用customers[$index]访问客户对象数组。 请看下面的演示或这个jsfiddle 。 angular.module('App', []) .controller("myCtrl", function($scope){ $scope.tickets = [ {code:'1', city:'Istanbul', value:10.0}, {code:'2', city:'London', value:50.0 ...
-
AngularJS:带链接的表(AngularJS: Table with links)[2023-01-15]
-
组合2个jsons对象(Combining 2 jsons objects)[2022-10-17]
从Prototype.js框架中查看Object.extend方法的源代码: https://github.com/sstephenson/prototype/blob/master/src/prototype/lang/object.js#L88 function extend(destination, source) { for (var property in source) { destination[property] = source[property]; } } 用法是... ... -
也许你可以尝试考虑如何将列转换为行,并在你的应用程序的哪一点做到这一点。 我建议在SQL级别上执行它。 检查此SQL Server:列到行或这一个SQL查询将列转换为行 如果你想用JavaScript做,请看一下javascript中矩阵的列(换位)的交换行 Probably you can try to think how to convert columns to rows and in which point of App you will do it. I recommend to do it at ...
-
在angularjs中呈现表格(Render table in angularjs)[2021-07-30]
您需要为标题迭代一次键,然后迭代行的值。