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.

3
  • @ug_ I don't want to create a static array but a arraylist to which the values will be added at runtime. Commented Oct 23, 2015 at 6: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. Commented Oct 24, 2015 at 11:26
  • See also stackoverflow.com/q/5003142 Commented Oct 24, 2015 at 20:49

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.