Jsp defines the value

<script type="application/javascript"> var dataList= "${data.dataList}"; </script> 

In the connected js choose

 $(document).ready(function(){ console.log(dataList); } 

In the console as a result

 [ru.test.TestClass@253d1594, ru.test.TestClass@59cfed2c, ru.test.TestClass@525614c0, ru.test.TestClass@47381287] 

What am I doing wrong? I need the values ​​of the object list. How to process the list of values?

  • Possibly override the toString method of your TestClass - JVic

1 answer 1

In the current implementation, you call the default method toString of the dataList object, which, apparently, is an object of the ArrayList class.

In order to fulfill your plans, you need:

  • either create a class from ArrayList, and override the toString method
  • or convert the dataList to a string in the form of JSON (or to the js array type), and only then transfer it to jsp
  • either bypass the dataList right in jsp

Here are all the examples: https://stackoverflow.com/questions/17440164/converting-a-java-arraylist-of-strings-to-a-javascript-array