0

I have a called a Servlet and I am sending an ArrayList with request attribute from Servlet to JSP. I am calling a js function from the same JSP in which I am passing the ArrayList as a param to the js function. I want to retrieve the values from this ArrayList.

Code as follow:

<c:if test="${currentPage lt noOfPages}">   
    <a onclick="OnNextButtonClick(${currentPage},'${al}');">
       <Next>
    </a>
</c:if>   
   //Here al is the ArrayList

<script type="text/javascript"> 
function OnNextButtonClick(currentPage,al)
{
  alert("current page == " + currentPage );
  alert("current page == " + al);

  var arr = new Array();
  var arr = al.split(','); 
  alert(arr);
}

This arr is giving me values as follows:

[com.package@1def,com.package@fkbe23,com.package@546fhfg]

I want the values stored at this location.

Can someone help me?

6
  • 2
    And I want a pony. Now what is your question. (Hint: "Can someone help me?" is not a question.) Commented Jan 18, 2017 at 6:57
  • I think the values of arr is object. extract it by using . and the members of that object you want to retrieve. Commented Jan 18, 2017 at 6:58
  • @LKTN.25 I tried it... I did arr[1].id ....It gave me an undefined as a value. Commented Jan 18, 2017 at 7:05
  • @JoeC I want the values stored at the locations mentioned above. Commented Jan 18, 2017 at 7:06
  • That is not a question. It's a wish list. Commented Jan 18, 2017 at 7:08

1 Answer 1

1

First of all List obj = dao.listimpl();this is java code you have pasted, try to paste the exact object which you trying to iterate.

Though i would recommend use a very lightweight javascript library Loadash which is very handy, when you are dealing with array/objects and looping through these items and many more util methods.

_.forOwn(obj, function(value, key) { } );

Loadash - forOwn

Iterates over own enumerable string keyed properties of an object and invokes iteratee for each property. The iteratee is invoked with three arguments: (value, key, object). Iteratee functions may exit iteration early by explicitly returning false

Sign up to request clarification or add additional context in comments.

Comments

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.