Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用AngularJS表单将JSON发送到Struts2操作?_Javascript_Json_Angularjs_Struts2 - Fatal编程技术网

Javascript 如何使用AngularJS表单将JSON发送到Struts2操作?

Javascript 如何使用AngularJS表单将JSON发送到Struts2操作?,javascript,json,angularjs,struts2,Javascript,Json,Angularjs,Struts2,如何使用AngularJS表单将JSON发送到Struts2操作 我的代码: 我的struts.xml <package name="default" extends="json-default"> <interceptors> <interceptor-stack name="defaultStack"> <interceptor-ref name="json">

如何使用AngularJS表单将JSON发送到Struts2操作

我的代码:

我的struts.xml

<package name="default" extends="json-default">

    <interceptors>
        <interceptor-stack name="defaultStack">
            <interceptor-ref name="json">
                <param name="enableSMD">true</param>
            </interceptor-ref>
        </interceptor-stack>
    </interceptors>

    <default-interceptor-ref name="defaultStack" />

    <action name="angularAction" class="actions.CustomerAction" method="findCustomer" >
        <result type="json">
              <param name="root">customer</param>
              <param name="excludeNullProperties">true</param>
              <param name="noCache">true</param>
        </result>
    </action>

</package>
我的Struts2动作

public class ClienteAction extends ActionSupport {

    private List<Customer> jsonCustomer;

    public List<Customer> getJsonCustomer() {
        return jsonCustomer;
    }


    public void setJsonCustomer(List<Customer> jsonCustomer) {
        this.jsonCustomer = jsonCustomer;
    }

    public String findCustomer() {

        List<Customer> jc = getJsonCustomer();

        return SUCCESS;

    }

}

它不起作用!angularAction中的变量jsonCustomer为null

我是个有棱角的新手。我使用的是本教程,但不是jquery


谢谢你的帮助

用于正确装载struts URL。另外,通过指定什么不起作用以及如何起作用来编辑您的问题,然后发布错误消息、stacktraces、javascript控制台错误等。还要确保您正确配置了拦截器堆栈并包含了所有需要的库。您真的想/需要发送json吗?嗨,Aleksandr M,我是angular的新手。向Struts发送表单数据的最佳方法是什么?
public class ClienteAction extends ActionSupport {

    private List<Customer> jsonCustomer;

    public List<Customer> getJsonCustomer() {
        return jsonCustomer;
    }


    public void setJsonCustomer(List<Customer> jsonCustomer) {
        this.jsonCustomer = jsonCustomer;
    }

    public String findCustomer() {

        List<Customer> jc = getJsonCustomer();

        return SUCCESS;

    }

}
angular.module('myApp', []);

angular.module('myApp').
controller('MyController',  function ($scope, $http) {
    $scope.getDataFromServer = function(customer) {

        var data1 = JSON.stringify(customer);

            $http({
                url: 'angularAction?jasonCustomer=' + data1,
                method: 'GET'
            }).then (function successCallback(response) {
                $scope.customer = response.data;                    

            }, function errorCallback(response) {
                console.log(response.data) ;
            })      

        };
    });