从Servlet传递数组到PHP

I have a Servlet that gets values from a payment DB
ex. SELECT * FROM PAYMENT;
ID = 1 2 3
Amount = 10.00 - 20.00 - 30.00

I have them stored in an array called paymentHistoryArray. Now I need to access them on a paymentPage.PHP I don't know the best way to accomplish this / or to loop accessing these values. Please help. The example code I follow uses:

response.sendRedirect("http://localhost/PHPwithDB/success_page.php" + "?id=" + id);

But this is not an array, how does 1 send an array from a servlet?

You can use an AJAX or a basic post method.

Just create an AJAX (or a basic POST call) which sends a request to the server which contains the Servlet (localhost or not).

You can construct a JSON object there and you can return it as a part of the response.

Then you can parse through the JSON object with a basic for loop, and use the data as you like.

Example (using the jQuery library):

$.ajax(
{
    type : 'post',
    url : 'folder/ServletName',
    dataType: 'json',
    contentType: 'text/plain',
    async: false,
    data : 
    {
        'request' : true
    },
    success : function(data)
    {
        var id = '';

        for(var i = 0; i < data.length; i++)
        {
            id = data[i].id;
            // Use id or other variables that you know of
        }
    },
    complete : function(data)
    {
    }
});

A similar method with coffeecsript (a little bit different)

$.ajax
     type: "POST",
     url : "folder/ServletName#
     data : JSON.stringify({"request" : true})
     dataType: "json"
     contentType: "text/plain"
     async: false
     error: (jqXHR, textStatus, errorThrown) ->
         $('#div').append "AJAX Error: #{textStatus}"
     success: (data, textStatus, jqXHR) ->
         for foo in data
              id= foo.id
              $("#div").html(id)

I hope that helps, I'm going to sleep but will check around tomorrow.