0

1) Is there any way we can create a arraylist using jstl? I'm new to jstl and this might be an silly question but I didn't found a way yet to do the same

Like in jsp we may create like the code below.

<%List<Integer> priceList = new ArrayList<Integer>();%>
<%for(DisplayModel displayModel:displayModelList)
{
priceList.add(displayModel.getPrice());%>
SOME HTML CODE
<%priceList.add(displayModel.getPrice());%>
SOME HTML CODE
<%}%>

How can the above code be implemented using jstl?

2) And how can we use the above declared list in JavaScript but using jstl

<script type='text/javascript'>
var priceFrom=<%=priceList.get(0)%>;
</script>

The question that has been answered as duplicate adds all the values to the array at once but in my case the values are to be added one by one as per there occurrence. And I want to create a arraylist not a array.

halfer
  • 19,824
  • 17
  • 99
  • 186
Droy
  • 173
  • 2
  • 17
  • @ug_ I don't want to create a static array but a arraylist to which the values will be added at runtime. – Droy Oct 23 '15 at 06:32
  • 2
    That's not something you should do with the JSTL. A JSP is a view component. It's used to generate HTML from data stored in the request. Creating a list and populating it is the job of the controller, written in Java, and executed before the JSP. – JB Nizet Oct 24 '15 at 11:26
  • See also http://stackoverflow.com/q/5003142 – BalusC Oct 24 '15 at 20:49

0 Answers0