0

I am getting an arraylist of objects from Java class and I want to pass this arraylist to a javascript function and get each object's properties inside the javascript function.

Please help me how to extract the value of the attributes inside the object.

Following is the code which I am using

`<script type="text/javascript">
var stats=new Array();
var i=0;
<%JobStats jobstat=new JobStats();
ArrayList<JobStats> stats=jobstat.Consolidate();
for(int i=0;i<stats.size();i++)
{
%>
stats[i]="<%=stats.get(i)%>";
i=i+1;
<%}%>
loadstats(stats);
</script>`
/* Javascript function*/
var array=new Array();
function loadstats(stats)
{

    array=stats[0];
    for(var key in array)
        {
        document.write(array[key]);
        }

}
1

1 Answer 1

0

One of the ways to comunicate betweet Java and javascript is using JSON. Javascript supports JSON natively in most modern browsers and in Java you can use Simple JSON

You can transfer JSON Objects an Arrays between both languages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.