angularsjs 대상 배열 의 요청 및 수신
1963 단어 AngularJs
function IndexController($scope,$http){
$scope.data=[{
name:'12118'
,age:'23'
}];
$scope.add =function(){
var postData = "?name="+JSON.stringify($scope.data)
+"&"+"age="+$scope.data.age;
var url = "LoginServlet.do" + postData;
$http.post(url).success(function(data)
{
alert(data[0].name);
});
};
}
자바 코드
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String data = request.getParameter("name");
JSONArray json=JSONArray.fromObject(data);
PrintWriter pw = response.getWriter();
pw.write(json.toString());
}