3

I am having an ArrayList<String> reportNames which i am sending as request.setAttribute("reportNames", reportNames);

How to assign ArrayList values to my javascript array on Jsp.

 var MyReports = [<%reportNames%>];
2
  • You have to convert your array list to JSON Commented Jan 28, 2016 at 10:26
  • I could find a similar problem in the below link. Hope it helps you.stackoverflow.com/questions/17440164/… Commented Jan 28, 2016 at 10:31

1 Answer 1

2

You could do this like bellow using JSP c:forEach and Javascript push().


Sample Code:

var MyReports  = [];
<c:forEach var="reportName" items="${reportNames}">
  MyReports.push(${reportName});
</c:forEach>
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.