I have two arraylists in my class and I want to send it to my JSP and then iterate the elements in arraylist in a select tag.
Here is my class:
packa
It would be better to use a java.util.Map
to store the key and values instead of two ArrayList
, like:
Map foods = new HashMap();
// here key stores the food codes
// and values are that which will be visible to the user in the drop-down
foods.put("man", "mango");
foods.put("app", "apple");
foods.put("gra", "grapes");
// if this is your servlet or action class having access to HttpRequest object then
httpRequest.setAttribute("foods", foods); // so that you can retrieve in JSP
Now to iterate the map in the JSP use:
Or without JSTL:
To know more about iterating with JSTL here is a good SO answer and here is a good tutorial about how to use JSTL in general.