Code Hungry
Code Hungry

Reputation: 4000

Arraylist<String> to javascript array in jsp

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%>];

Upvotes: 3

Views: 2472

Answers (1)

mmuzahid
mmuzahid

Reputation: 2270

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>

Upvotes: 2

Related Questions