Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


how to get data using angular http get from action class in struts2 project


how to get data using angular http get from action class in struts2 project  using -'angularjs'

I am developing project using angular and struts2 + maven.
this is my action class

package com.ai.action;

import com.ai.model.PersonData;
import com.ai.model.Village;
import com.ai.service.PersonService;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class AngularAction implements Action {

private Map session = ActionContext.getContext().getSession();
private Logger logger = LoggerFactory.getLogger(PersonAction.class);

private List<Village> STSarray;
@Autowired
private PersonService  personService;

public String execute()
{
    setSTSarray(personService.getAllVillage());
    logger.info("save method {}",getSTSarray());
    return SUCCESS;
}

public List<Village> getSTSarray() {
    return STSarray;
}

public void setSTSarray(List<Village> STSarray) {
    this.STSarray = STSarray;
}

}


Here i loaded data to
    list
using DAO with hibernate. Data added successfully to array.
then i want to get this data to jsp page.

Struts.xml

    <action name="angularAction" class="com.ai.action.AngularAction">
        <result type="json">
            <param name="root">personData</param>
            <param name="excludeNullProperties">true</param>
            <param name="noCache">true</param>
        </result>
    </action>


this is my jsp page.

<!DOCTYPE html>
<html ng-app="demo">
<head>
<meta charset="ISO-8859-1">
<title>AJAX with Struts 2 using AngularJS</title>
<link href="css/bootstrap.css" rel="stylesheet" />
<link href="css/bootstrap-theme.css" rel="stylesheet" />
<script type="text/javascript" src="scripts/angular.min.js"></script>
<script>
    var app = angular.module('demo', []);

    function MyController($scope, $http) {
        $scope.getDataFromServer = function() {
            $http.get("angularAction").success(

                    function(data, status, headers, config) {

                        $scope.itemsdata = data;
                        console.log($scope.person);
                    }).error(function(data, status, headers, config) {

                    });
        };
    };
</script>
</head>
<body ng-controller="demoCtrl">
<table class="table table-striped">
<p><button data-ng-click="loadData()">
    Fetch data from server
</button></p>
<thead>
<tr>
    <th>Country</th>
    <th>Name</th>
    <th>Size</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in itemsdata">
    <td>{{item.country}}</td>
    <td>{{item.name}}</td>
    <td>{{item.size}}</td>
</tr>
</tbody>
 </table>
 </body>
</html>


But
    console.log($scope.person);
give me null.please help.
    

asked Oct 6, 2015 by okesh.badhiye
0 votes
3 views



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...