Iterate ArrayList in JSP

后端 未结 5 1645
遥遥无期
遥遥无期 2020-12-03 15:54

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         


        
5条回答
  •  萌比男神i
    2020-12-03 16:00

    There are multiple ways this can be done (with some changes in your scheme)

    Using JSTL:

    1. Create a bean with two fields as food and food_code

      public class Food{ private String food; private String food_code; // Setter/getters follows }

    Now the arraylist available on the page will be list Food objects. In the JSP code, you can use following:

    
    

    If you are using struts:

    
    
    
    

    Here list is object key which will be used to retrieve the list from context (page/session)

提交回复
热议问题