Access map value in EL using a variable as key

前端 未结 5 961
野性不改
野性不改 2020-12-14 03:08

I have a Map in EL as ${map} and I am trying to get the value of it using a key which is by itself also an EL variable ${key} with the

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-14 03:43

    You can put the key-value in a map on Java side and access the same using JSTL on JSP page as below:

    Prior java 1.7:

    Map map = new HashMap();
    map.put("key","value");
    

    Java 1.7 and above:

    Map map = new HashMap<>();
    map.put("key","value");
    

    JSP Snippet:

    
    

提交回复
热议问题