anto
anto

Reputation: 325

How to get value from arraylist to be displayed on jsp using jstl

I am newbie please help in resolving this,here i need to display data from array list to be displayed in jsp using jstl. I have created one utill class where it fetch data from database and sets the value in bean and i added that bean to arraylist like

arl.add(devTechBean);

and returns the array list to modelandview mylist method where it passes the arraylist to jsp using

ModelAndView mnv = 
new ModelAndView("swl_mySoftwareList","mySoftwareList",mySoftwareList);

in the jsp i access the array list like

${mySoftwareList.assetNumber}

(where assetnumber is the value i got from bean). My question is how to access the arraylist in jsp using jstl and i need to know where to map that modelandview mylist method in spring as find that method is not called in jsp.Please help me resolving this.

Upvotes: 0

Views: 9268

Answers (1)

JB Nizet
JB Nizet

Reputation: 691765

mySoftwareList is an ArrayList. SO if you write ${mySoftwareList.assetNumber}, you're asking the container to call the method getAssetNumber() on an object of type ArrayList. ArrayList doesn't have such a method.

If you want to call this method on every element of the list, then iterate through the list:

<c:forEach var="element" items="${mySoftwareList}>
    ${element.assetNumber}<br/>
</c:forEach>

If you only have one instance, then simply don't store it in a list and pass it directly to the view:

new ModelAndView("swl_mySoftwareList","devTechBean", devTechBean);

${devTechBean.assetNumber}

Upvotes: 2

Related Questions